48 #include "llvm/ADT/SmallString.h"
49 #include "llvm/TargetParser/Triple.h"
54 #include <unordered_map>
56 using namespace clang;
72 TypeNameValidatorCCC(
bool AllowInvalid,
bool WantClass =
false,
73 bool AllowTemplates =
false,
74 bool AllowNonTemplates =
true)
75 : AllowInvalidDecl(AllowInvalid), WantClassName(WantClass),
76 AllowTemplates(AllowTemplates), AllowNonTemplates(AllowNonTemplates) {
77 WantExpressionKeywords =
false;
78 WantCXXNamedCasts =
false;
79 WantRemainingKeywords =
false;
84 if (!AllowInvalidDecl && ND->isInvalidDecl())
88 return AllowTemplates;
90 bool IsType = isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
94 if (AllowNonTemplates)
100 auto *RD = dyn_cast<CXXRecordDecl>(ND);
101 if (!RD || !RD->isInjectedClassName())
103 RD = cast<CXXRecordDecl>(RD->getDeclContext());
104 return RD->getDescribedClassTemplate() ||
105 isa<ClassTemplateSpecializationDecl>(RD);
111 return !WantClassName && candidate.
isKeyword();
114 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
115 return std::make_unique<TypeNameValidatorCCC>(*
this);
119 bool AllowInvalidDecl;
122 bool AllowNonTemplates;
134 case tok::kw___int64:
135 case tok::kw___int128:
137 case tok::kw_unsigned:
145 case tok::kw__Float16:
146 case tok::kw___float128:
147 case tok::kw___ibm128:
148 case tok::kw_wchar_t:
150 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
151 #include "clang/Basic/TransformTypeTraits.def"
152 case tok::kw___auto_type:
155 case tok::annot_typename:
156 case tok::kw_char16_t:
157 case tok::kw_char32_t:
159 case tok::annot_decltype:
160 case tok::kw_decltype:
161 return getLangOpts().CPlusPlus;
163 case tok::kw_char8_t:
164 return getLangOpts().Char8;
174 enum class UnqualifiedTypeNameLookupResult {
185 static UnqualifiedTypeNameLookupResult
190 return UnqualifiedTypeNameLookupResult::NotFound;
192 UnqualifiedTypeNameLookupResult FoundTypeDecl =
193 UnqualifiedTypeNameLookupResult::NotFound;
196 if (
auto *BaseTT =
Base.getType()->getAs<
TagType>())
197 BaseRD = BaseTT->getAsCXXRecordDecl();
201 if (!TST || !TST->isDependentType())
203 auto *TD = TST->getTemplateName().getAsTemplateDecl();
206 if (
auto *BasePrimaryTemplate =
207 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) {
209 BaseRD = BasePrimaryTemplate;
210 else if (
auto *CTD = dyn_cast<ClassTemplateDecl>(TD)) {
212 CTD->findPartialSpecialization(
Base.getType()))
220 if (!isa<TypeDecl>(ND))
221 return UnqualifiedTypeNameLookupResult::FoundNonType;
222 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
224 if (FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound) {
226 case UnqualifiedTypeNameLookupResult::FoundNonType:
227 return UnqualifiedTypeNameLookupResult::FoundNonType;
228 case UnqualifiedTypeNameLookupResult::FoundType:
229 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
231 case UnqualifiedTypeNameLookupResult::NotFound:
238 return FoundTypeDecl;
246 UnqualifiedTypeNameLookupResult FoundTypeDecl =
247 UnqualifiedTypeNameLookupResult::NotFound;
249 DC && FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound;
250 DC = DC->getParent()) {
253 RD = dyn_cast<CXXRecordDecl>(DC);
257 if (FoundTypeDecl != UnqualifiedTypeNameLookupResult::FoundType)
263 S.
Diag(NameLoc, diag::ext_found_in_dependent_base) << &II;
284 bool WantNontrivialTypeSourceInfo =
true) {
286 case Type::DeducedTemplateSpecialization:
288 case Type::InjectedClassName:
291 case Type::UnresolvedUsing:
296 case Type::ObjCInterface:
297 case Type::ObjCTypeParam:
298 case Type::TemplateTypeParm:
301 llvm_unreachable(
"Unexpected Type Class");
309 if (!WantNontrivialTypeSourceInfo)
313 Builder.pushTypeSpec(T).setNameLoc(NameLoc);
330 bool HasTrailingDot,
ParsedType ObjectTypePtr,
331 bool IsCtorOrDtorName,
332 bool WantNontrivialTypeSourceInfo,
333 bool IsClassTemplateDeductionContext,
337 bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
338 getLangOpts().CPlusPlus17 && !IsCtorOrDtorName &&
339 !isClassName && !HasTrailingDot;
346 LookupCtx = computeDeclContext(ObjectType);
348 LookupCtx = computeDeclContext(*SS,
false);
351 if (isDependentScopeSpecifier(*SS)) {
364 !isClassName && !IsCtorOrDtorName)
366 bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
367 if (IsImplicitTypename) {
370 Diag(QualifiedLoc, diag::warn_cxx17_compat_implicit_typename);
372 Diag(QualifiedLoc, diag::ext_implicit_typename)
379 if (WantNontrivialTypeSourceInfo)
395 RequireCompleteDeclContext(*SS, LookupCtx))
409 LookupQualifiedName(Result, LookupCtx);
411 if (ObjectTypePtr && Result.empty()) {
418 LookupName(Result, S);
422 LookupName(Result, S);
426 if (Result.empty() && getLangOpts().MSVCCompat && (!SS || SS->
isEmpty())) {
435 switch (Result.getResultKind()) {
439 TypeNameValidatorCCC CCC(
true, isClassName,
440 AllowDeducedTemplate);
442 S, SS, CCC, CTK_ErrorRecovery);
445 bool MemberOfUnknownSpecialization;
454 if (Correction && (NNS || NewII != &II) &&
459 isTemplateName(S, *NewSSPtr,
false,
TemplateName,
nullptr,
false,
460 Template, MemberOfUnknownSpecialization))) {
462 isClassName, HasTrailingDot, ObjectTypePtr,
464 WantNontrivialTypeSourceInfo,
465 IsClassTemplateDeductionContext);
467 diagnoseTypo(Correction,
468 PDiag(diag::err_unknown_type_or_class_name_suggest)
469 << Result.getLookupName() << isClassName);
472 *CorrectedII = NewII;
481 Result.suppressDiagnostics();
491 Result.suppressDiagnostics();
497 Res != ResEnd; ++Res) {
499 if (isa<TypeDecl, ObjCInterfaceDecl, UnresolvedUsingIfExistsDecl>(
506 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Res);
518 Result.suppressDiagnostics();
529 IIDecl = Result.getFoundDecl();
530 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Result.begin());
534 assert(IIDecl &&
"Didn't find decl");
537 if (
TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
541 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
542 auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
543 if (!isClassName && !IsCtorOrDtorName && LookupRD && FoundRD &&
544 FoundRD->isInjectedClassName() &&
546 Diag(NameLoc, diag::err_out_of_line_qualified_id_type_names_constructor)
549 DiagnoseUseOfDecl(IIDecl, NameLoc);
552 MarkAnyDeclReferenced(TD->getLocation(), TD,
false);
554 (void)DiagnoseUseOfDecl(IDecl, NameLoc);
557 FoundUsingShadow =
nullptr;
558 }
else if (
auto *UD = dyn_cast<UnresolvedUsingIfExistsDecl>(IIDecl)) {
559 (void)DiagnoseUseOfDecl(UD, NameLoc);
562 }
else if (AllowDeducedTemplate) {
564 assert(!FoundUsingShadow || FoundUsingShadow->
getTargetDecl() == TD);
570 FoundUsingShadow =
nullptr;
576 Result.suppressDiagnostics();
580 if (FoundUsingShadow)
583 return buildNamedType(*
this, SS, T, NameLoc, WantNontrivialTypeSourceInfo);
591 auto *ND = dyn_cast<NamespaceDecl>(DC);
592 if (ND && !ND->isInline() && !ND->isAnonymousNamespace())
594 else if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
596 RD->getTypeForDecl());
597 else if (isa<TranslationUnitDecl>(DC))
600 llvm_unreachable(
"something isn't in TU scope?");
611 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
612 if (MD->getParent()->hasAnyDependentBases())
620 bool IsTemplateTypeArg) {
621 assert(getLangOpts().MSVCCompat &&
"shouldn't be called in non-MSVC mode");
624 if (IsTemplateTypeArg && getCurScope()->isTemplateParamScope()) {
633 Diag(NameLoc, diag::ext_ms_delayed_template_argument) << &II;
639 RD->getTypeForDecl());
643 Diag(NameLoc, diag::ext_undeclared_unqual_id_with_dependent_base) << &II
663 return CreateParsedType(T, Builder.getTypeSourceInfo(Context, T));
674 LookupName(R, S,
false);
678 switch (TD->getTagKind()) {
705 if (CurContext->isRecord()) {
715 return S->isFunctionPrototypeScope();
717 return CurContext->isFunctionOrMethod() || S->isFunctionPrototypeScope();
725 bool IsTemplateName) {
730 SuggestedType =
nullptr;
734 TypeNameValidatorCCC CCC(
false,
false,
739 CCC, CTK_ErrorRecovery)) {
741 bool CanRecover = !IsTemplateName;
742 if (Corrected.isKeyword()) {
744 diagnoseTypo(Corrected,
745 PDiag(IsTemplateName ? diag::err_no_template_suggest
746 : diag::err_unknown_typename_suggest)
748 II = Corrected.getCorrectionAsIdentifierInfo();
751 if (!SS || !SS->
isSet()) {
752 diagnoseTypo(Corrected,
753 PDiag(IsTemplateName ? diag::err_no_template_suggest
754 : diag::err_unknown_typename_suggest)
756 }
else if (
DeclContext *DC = computeDeclContext(*SS,
false)) {
757 std::string CorrectedStr(Corrected.getAsString(getLangOpts()));
758 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
759 II->
getName().equals(CorrectedStr);
760 diagnoseTypo(Corrected,
762 ? diag::err_no_member_template_suggest
763 : diag::err_unknown_nested_typename_suggest)
764 << II << DC << DroppedSpecifier << SS->
getRange(),
767 llvm_unreachable(
"could not have corrected a typo here");
774 if (Corrected.getCorrectionSpecifier())
775 tmpSS.
MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
779 getTypeName(*Corrected.getCorrectionAsIdentifierInfo(), IILoc, S,
780 tmpSS.
isSet() ? &tmpSS : SS,
false,
false,
nullptr,
787 if (getLangOpts().
CPlusPlus && !IsTemplateName) {
790 Name.setIdentifier(II, IILoc);
793 bool MemberOfUnknownSpecialization;
794 if (isTemplateName(S, SS ? *SS : EmptySS,
false,
795 Name,
nullptr,
true, TemplateResult,
797 diagnoseMissingTemplateArguments(TemplateResult.
get(), IILoc);
806 Diag(IILoc, IsTemplateName ? diag::err_no_template
807 : diag::err_unknown_typename)
809 else if (
DeclContext *DC = computeDeclContext(*SS,
false))
810 Diag(IILoc, IsTemplateName ? diag::err_no_member_template
811 : diag::err_typename_nested_not_found)
816 }
else if (isDependentScopeSpecifier(*SS)) {
817 unsigned DiagID = diag::err_typename_missing;
818 if (getLangOpts().MSVCCompat && isMicrosoftMissingTypename(SS, S))
819 DiagID = diag::ext_typename_missing;
826 *SS, *II, IILoc).
get();
829 "Invalid scope specifier has already been diagnosed");
837 NextToken.
is(tok::less);
840 if (isa<TypeDecl>(*I) || isa<ObjCInterfaceDecl>(*I))
843 if (CheckTemplate && isa<TemplateDecl>(*I))
857 StringRef FixItTagName;
858 switch (Tag->getTagKind()) {
860 FixItTagName =
"class ";
864 FixItTagName =
"enum ";
868 FixItTagName =
"struct ";
872 FixItTagName =
"__interface ";
876 FixItTagName =
"union ";
880 StringRef TagName = FixItTagName.drop_back();
881 SemaRef.
Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
882 << Name << TagName << SemaRef.
getLangOpts().CPlusPlus
887 SemaRef.
Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
902 const Token &NextToken,
907 assert(NextToken.
isNot(tok::coloncolon) &&
908 "parse nested name specifiers before calling ClassifyName");
910 isCurrentClassName(*Name, S, &SS)) {
918 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
919 LookupParsedName(Result, S, &SS, !CurMethod);
926 if (Result.empty() && SS.
isEmpty() && getLangOpts().MSVCCompat) {
937 DeclResult Ivar = LookupIvarInObjCMethod(Result, S, Name);
941 return NameClassification::NonType(cast<NamedDecl>(Ivar.
get()));
945 LookupBuiltin(Result);
948 bool SecondTry =
false;
949 bool IsFilteredTemplateName =
false;
952 switch (Result.getResultKind()) {
956 if (SS.
isEmpty() && NextToken.
is(tok::l_paren)) {
960 return NameClassification::UndeclaredNonType();
976 if (getLangOpts().implicitFunctionsAllowed()) {
977 if (
NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *Name, S))
978 return NameClassification::NonType(D);
989 return NameClassification::UndeclaredTemplate(Template);
995 if (!getLangOpts().
CPlusPlus && !SecondTry &&
1002 if (!SecondTry && CCC) {
1005 CorrectTypo(Result.getLookupNameInfo(), Result.getLookupKind(), S,
1006 &SS, *CCC, CTK_ErrorRecovery)) {
1007 unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
1008 unsigned QualifiedDiag = diag::err_no_member_suggest;
1010 NamedDecl *FirstDecl = Corrected.getFoundDecl();
1011 NamedDecl *UnderlyingFirstDecl = Corrected.getCorrectionDecl();
1012 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1013 UnderlyingFirstDecl && isa<TemplateDecl>(UnderlyingFirstDecl)) {
1014 UnqualifiedDiag = diag::err_no_template_suggest;
1015 QualifiedDiag = diag::err_no_member_template_suggest;
1016 }
else if (UnderlyingFirstDecl &&
1017 (isa<TypeDecl>(UnderlyingFirstDecl) ||
1018 isa<ObjCInterfaceDecl>(UnderlyingFirstDecl) ||
1019 isa<ObjCCompatibleAliasDecl>(UnderlyingFirstDecl))) {
1020 UnqualifiedDiag = diag::err_unknown_typename_suggest;
1021 QualifiedDiag = diag::err_unknown_nested_typename_suggest;
1025 diagnoseTypo(Corrected, PDiag(UnqualifiedDiag) << Name);
1027 std::string CorrectedStr(Corrected.getAsString(getLangOpts()));
1028 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
1029 Name->getName().equals(CorrectedStr);
1030 diagnoseTypo(Corrected, PDiag(QualifiedDiag)
1031 << Name << computeDeclContext(SS,
false)
1032 << DroppedSpecifier << SS.
getRange());
1036 Name = Corrected.getCorrectionAsIdentifierInfo();
1039 if (Corrected.isKeyword())
1045 Result.setLookupName(Corrected.getCorrection());
1047 Result.addDecl(FirstDecl);
1055 LookupIvarInObjCMethod(Result, S, Ivar->getIdentifier());
1059 return NameClassification::NonType(Ivar);
1067 Result.suppressDiagnostics();
1085 return NameClassification::DependentNonType();
1094 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1095 hasAnyAcceptableTemplateNames(Result,
true,
1108 FilterAcceptableTemplateNames(Result);
1109 if (!Result.isAmbiguous()) {
1110 IsFilteredTemplateName =
true;
1119 if (getLangOpts().
CPlusPlus && NextToken.
is(tok::less) &&
1120 (IsFilteredTemplateName ||
1121 hasAnyAcceptableTemplateNames(
1136 if (!IsFilteredTemplateName)
1137 FilterAcceptableTemplateNames(Result);
1139 bool IsFunctionTemplate;
1142 if (Result.end() - Result.begin() > 1) {
1143 IsFunctionTemplate =
true;
1146 }
else if (!Result.empty()) {
1147 auto *TD = cast<TemplateDecl>(getAsTemplateNameDecl(
1148 *Result.begin(),
true,
1150 IsFunctionTemplate = isa<FunctionTemplateDecl>(TD);
1151 IsVarTemplate = isa<VarTemplateDecl>(TD);
1154 dyn_cast<UsingShadowDecl>(*Result.begin());
1155 assert(!FoundUsingShadow ||
1156 TD == cast<TemplateDecl>(FoundUsingShadow->
getTargetDecl()));
1166 IsFunctionTemplate =
true;
1170 if (IsFunctionTemplate) {
1174 Result.suppressDiagnostics();
1176 return NameClassification::FunctionTemplate(Template);
1179 return IsVarTemplate ? NameClassification::VarTemplate(Template)
1180 : NameClassification::TypeTemplate(Template);
1185 if (
const auto *USD = dyn_cast<UsingShadowDecl>(Found))
1190 NamedDecl *FirstDecl = (*Result.begin())->getUnderlyingDecl();
1192 DiagnoseUseOfDecl(
Type, NameLoc);
1193 MarkAnyDeclReferenced(
Type->getLocation(),
Type,
false);
1194 return BuildTypeFor(
Type, *Result.begin());
1201 dyn_cast<ObjCCompatibleAliasDecl>(FirstDecl))
1202 Class = Alias->getClassInterface();
1206 DiagnoseUseOfDecl(Class, NameLoc);
1208 if (NextToken.
is(tok::period)) {
1211 Result.suppressDiagnostics();
1219 if (isa<ConceptDecl>(FirstDecl))
1220 return NameClassification::Concept(
1223 if (
auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(FirstDecl)) {
1224 (void)DiagnoseUseOfDecl(EmptyD, NameLoc);
1229 if (isa<TemplateDecl>(FirstDecl) && !isa<FunctionTemplateDecl>(FirstDecl) &&
1230 !isa<VarTemplateDecl>(FirstDecl))
1231 return NameClassification::TypeTemplate(
1236 bool NextIsOp = NextToken.
isOneOf(tok::amp, tok::star);
1237 if ((NextToken.
is(tok::identifier) ||
1242 DiagnoseUseOfDecl(
Type, NameLoc);
1243 return BuildTypeFor(
Type, *Result.begin());
1250 bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.
is(tok::l_paren));
1251 if (Result.isSingleResult() && !ADL &&
1253 return NameClassification::NonType(Result.getRepresentativeDecl());
1256 Result.suppressDiagnostics();
1259 Result.getLookupNameInfo(), ADL, Result.isOverloadedResult(),
1260 Result.begin(), Result.end()));
1266 assert(getLangOpts().
CPlusPlus &&
"ADL-only call in C?");
1268 LookupResult Result(*
this, Name, NameLoc, LookupOrdinaryName);
1269 return BuildDeclarationNameExpr(SS, Result,
true);
1276 bool IsAddressOfOperand) {
1279 NameInfo, IsAddressOfOperand,
1286 const Token &NextToken) {
1287 if (getCurMethodDecl() && SS.
isEmpty())
1289 return BuildIvarRefExpr(S, NameLoc, Ivar);
1293 Result.addDecl(Found);
1294 Result.resolveKind();
1296 bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.
is(tok::l_paren));
1297 return BuildDeclarationNameExpr(SS, Result, ADL,
true);
1303 auto *ULE = cast<UnresolvedLookupExpr>(E);
1304 if ((*ULE->decls_begin())->isCXXClassMember()) {
1306 SS.
Adopt(ULE->getQualifierLoc());
1309 LookupResult Result(*
this, ULE->getName(), ULE->getNameLoc(),
1310 LookupOrdinaryName);
1311 Result.setNamingClass(ULE->getNamingClass());
1312 for (
auto I = ULE->decls_begin(), E = ULE->decls_end(); I != E; ++I)
1313 Result.addDecl(*I, I.getAccess());
1314 Result.resolveKind();
1315 return BuildPossibleImplicitMemberExpr(SS,
SourceLocation(), Result,
1326 auto *TD = Name.getAsTemplateDecl();
1328 return TemplateNameKindForDiagnostics::DependentTemplate;
1329 if (isa<ClassTemplateDecl>(TD))
1330 return TemplateNameKindForDiagnostics::ClassTemplate;
1331 if (isa<FunctionTemplateDecl>(TD))
1332 return TemplateNameKindForDiagnostics::FunctionTemplate;
1333 if (isa<VarTemplateDecl>(TD))
1334 return TemplateNameKindForDiagnostics::VarTemplate;
1335 if (isa<TypeAliasTemplateDecl>(TD))
1336 return TemplateNameKindForDiagnostics::AliasTemplate;
1337 if (isa<TemplateTemplateParmDecl>(TD))
1338 return TemplateNameKindForDiagnostics::TemplateTemplateParam;
1339 if (isa<ConceptDecl>(TD))
1340 return TemplateNameKindForDiagnostics::Concept;
1341 return TemplateNameKindForDiagnostics::DependentTemplate;
1346 "The next DeclContext should be lexically contained in the current one.");
1352 assert(CurContext &&
"DeclContext imbalance!");
1354 CurContext = CurContext->getLexicalParent();
1355 assert(CurContext &&
"Popped translation unit!");
1364 CurContext = cast<TagDecl>(D)->getDefinition();
1365 assert(CurContext &&
"skipping definition of undefined tag");
1368 S->setEntity(CurContext->getLookupParent());
1373 CurContext =
static_cast<decltype(CurContext)
>(Context);
1396 assert(!S->getEntity() &&
"scope already has entity");
1399 Scope *Ancestor = S->getParent();
1401 assert(Ancestor->
getEntity() == CurContext &&
"ancestor context mismatch");
1407 if (S->getParent()->isTemplateParamScope()) {
1410 EnterTemplatedContext(S->getParent(), DC);
1415 assert(S->getEntity() == CurContext &&
"Context imbalance!");
1419 Scope *Ancestor = S->getParent();
1428 assert(S->isTemplateParamScope() &&
1429 "expected to be initializing a template parameter scope");
1452 unsigned ScopeDepth = getTemplateDepth(S);
1453 for (; S && S->isTemplateParamScope(); S = S->getParent(), --ScopeDepth) {
1457 cast<Decl>(DC)->getDescribedTemplateParams()) {
1458 unsigned DCDepth = TPL->getDepth() + 1;
1459 if (DCDepth > ScopeDepth)
1461 if (ScopeDepth == DCDepth)
1466 S->setLookupEntity(SearchDCAfterScope);
1480 "The next DeclContext should be lexically contained in the current one.");
1482 S->setEntity(CurContext);
1484 for (
unsigned P = 0, NumParams = FD->
getNumParams();
P < NumParams; ++
P) {
1489 IdResolver.AddDecl(Param);
1497 assert(CurContext &&
"DeclContext imbalance!");
1498 CurContext = CurContext->getLexicalParent();
1499 assert(CurContext &&
"Popped translation unit!");
1528 return ND->
hasAttr<OverloadableAttr>();
1531 return Previous.getFoundDecl()->hasAttr<OverloadableAttr>();
1541 while (S->getEntity() && S->getEntity()->isTransparentContext())
1548 CurContext->addDecl(D);
1556 if (isa<FunctionDecl>(D) &&
1557 cast<FunctionDecl>(D)->isFunctionTemplateSpecialization())
1562 IEnd = IdResolver.end();
1563 for (; I != IEnd; ++I) {
1566 IdResolver.RemoveDecl(*I);
1575 if (isa<LabelDecl>(D) && !cast<LabelDecl>(D)->isGnuLocal()) {
1579 for (I = IdResolver.begin(D->
getDeclName()); I != IEnd; ++I) {
1581 if (IDC == CurContext) {
1582 if (!S->isDeclScope(*I))
1584 }
else if (IDC->
Encloses(CurContext))
1588 IdResolver.InsertDeclAfter(I, D);
1590 IdResolver.AddDecl(D);
1592 warnOnReservedIdentifier(D);
1596 bool AllowInlineNamespace) {
1597 return IdResolver.isDeclInScope(D, Ctx, S, AllowInlineNamespace);
1604 if (ScopeDC->getPrimaryContext() == TargetDC)
1606 }
while ((S = S->getParent()));
1618 bool ConsiderLinkage,
1619 bool AllowInlineNamespace) {
1624 if (isDeclInScope(D, Ctx, S, AllowInlineNamespace))
1649 makeMergedDefinitionVisible(New);
1674 if (NewIsModuleInterface || OldIsModuleInterface) {
1680 << NewIsModuleInterface
1682 << OldIsModuleInterface
1713 if (!IsNewExported && !IsOldExported)
1719 assert(IsNewExported);
1727 Diag(New->
getLocation(), diag::err_redeclaration_non_exported) << New << S;
1735 if (CheckRedeclarationModuleOwnership(New, Old))
1738 if (CheckRedeclarationExported(New, Old))
1762 assert(getASTContext().isSameEntity(New, Old) &&
1763 "New and Old are not the same definition, we should diagnostic it "
1764 "immediately instead of checking it.");
1765 assert(
const_cast<Sema *
>(
this)->isReachable(New) &&
1766 const_cast<Sema *
>(
this)->isReachable(Old) &&
1767 "We shouldn't see unreachable definitions here.");
1815 return OldM == NewM;
1819 return isa<UsingShadowDecl>(D) ||
1820 isa<UnresolvedUsingTypenameDecl>(D) ||
1821 isa<UnresolvedUsingValueDecl>(D);
1848 return CD->isCopyConstructor();
1864 bool Sema::mightHaveNonExternalLinkage(
const DeclaratorDecl *D) {
1867 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(DC)){
1868 if (!RD->hasNameForLinkage())
1897 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1903 FD->getMemberSpecializationInfo() && !FD->isOutOfLine())
1906 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1911 if (FD->isInlined() && !
isMainFileLoc(*
this, FD->getLocation()))
1915 if (FD->doesThisDeclarationHaveABody() &&
1918 }
else if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1928 if (VD->isStaticDataMember() &&
1931 if (VD->isStaticDataMember() &&
1933 VD->getMemberSpecializationInfo() && !VD->isOutOfLine())
1936 if (VD->isInline() && !
isMainFileLoc(*
this, VD->getLocation()))
1945 return mightHaveNonExternalLinkage(D);
1952 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1954 if (FD !=
First && ShouldWarnIfUnusedFileScopedDecl(
First))
1958 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1960 if (VD !=
First && ShouldWarnIfUnusedFileScopedDecl(
First))
1964 if (ShouldWarnIfUnusedFileScopedDecl(D))
1965 UnusedFileScopedDecls.push_back(D);
1972 if (
auto *DD = dyn_cast<DecompositionDecl>(D)) {
1976 for (
auto *BD : DD->bindings())
1977 if (BD->isReferenced())
1985 if (D->
hasAttr<UnusedAttr>() || D->
hasAttr<ObjCPreciseLifetimeAttr>())
1988 if (isa<LabelDecl>(D))
1994 if (
const auto *R = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
1997 WithinFunction || (R->isLocalClass() && !R->isDependentType());
1998 if (!WithinFunction)
2001 if (isa<TypedefNameDecl>(D))
2005 if (!isa<VarDecl>(D) || isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D))
2009 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2011 const Expr *Init = VD->getInit();
2012 if (
const auto *Cleanups = dyn_cast_or_null<ExprWithCleanups>(Init))
2013 Init = Cleanups->getSubExpr();
2015 const auto *Ty = VD->getType().getTypePtr();
2020 if (TT->getDecl()->hasAttr<UnusedAttr>())
2026 if (
const auto *MTE = dyn_cast_or_null<MaterializeTemporaryExpr>(Init)) {
2027 if (MTE->getExtendingDecl()) {
2028 Ty = VD->getType().getNonReferenceType().getTypePtr();
2029 Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
2035 if (Ty->isIncompleteType() || Ty->isDependentType())
2040 Ty = Ty->getBaseElementTypeUnsafe();
2043 const TagDecl *Tag = TT->getDecl();
2044 if (Tag->
hasAttr<UnusedAttr>())
2047 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2048 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>())
2053 dyn_cast<CXXConstructExpr>(Init);
2056 if (!CD->
isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
2057 (VD->getInit()->isValueDependent() || !VD->evaluateValue()))
2063 if (Init->isTypeDependent()) {
2065 if (!Ctor->isTrivial())
2071 if (isa<CXXUnresolvedConstructExpr>(Init))
2085 if (isa<LabelDecl>(D)) {
2097 DiagnoseUnusedNestedTypedefs(
2106 for (
auto *TmpD : D->
decls()) {
2107 if (
const auto *T = dyn_cast<TypedefNameDecl>(TmpD))
2108 DiagnoseUnusedDecl(T, DiagReceiver);
2109 else if(
const auto *R = dyn_cast<RecordDecl>(TmpD))
2110 DiagnoseUnusedNestedTypedefs(R, DiagReceiver);
2125 if (
auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2128 UnusedLocalTypedefNameCandidates.insert(TD);
2136 if (isa<VarDecl>(D) && cast<VarDecl>(D)->isExceptionVariable())
2137 DiagID = diag::warn_unused_exception_param;
2138 else if (isa<LabelDecl>(D))
2139 DiagID = diag::warn_unused_label;
2141 DiagID = diag::warn_unused_variable;
2143 DiagReceiver(D->
getLocation(), PDiag(DiagID) << D << Hint);
2156 if (Ty->isReferenceType() || Ty->isDependentType())
2160 const TagDecl *Tag = TT->getDecl();
2161 if (Tag->
hasAttr<UnusedAttr>())
2165 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2166 if (!RD->hasAttr<WarnUnusedAttr>())
2174 if (VD->
hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType())
2180 if (VD->
hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType())
2183 auto iter = RefsMinusAssignments.find(VD);
2184 if (iter == RefsMinusAssignments.end())
2187 assert(iter->getSecond() >= 0 &&
2188 "Found a negative number of references to a VarDecl");
2189 if (iter->getSecond() != 0)
2191 unsigned DiagID = isa<ParmVarDecl>(VD) ? diag::warn_unused_but_set_parameter
2192 : diag::warn_unused_but_set_variable;
2193 DiagReceiver(VD->
getLocation(), PDiag(DiagID) << VD);
2202 bool Diagnose =
false;
2206 Diagnose = L->
getStmt() ==
nullptr;
2215 if (S->decl_empty())
return;
2217 "Scope shouldn't contain decls!");
2224 std::optional<SourceLocation> PreviousDeclLoc;
2229 DeclDiags.push_back(LocAndDiag{Loc, std::nullopt, std::move(PD)});
2234 DeclDiags.push_back(LocAndDiag{Loc, PreviousDeclLoc, std::move(PD)});
2237 for (
auto *TmpD : S->decls()) {
2238 assert(TmpD &&
"This decl didn't get pushed??");
2240 assert(isa<NamedDecl>(TmpD) &&
"Decl isn't NamedDecl?");
2244 if (!S->hasUnrecoverableErrorOccurred()) {
2245 DiagnoseUnusedDecl(D, addDiag);
2246 if (
const auto *RD = dyn_cast<RecordDecl>(D))
2247 DiagnoseUnusedNestedTypedefs(RD, addDiag);
2248 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2249 DiagnoseUnusedButSetDecl(VD, addDiag);
2250 RefsMinusAssignments.erase(VD);
2257 if (
LabelDecl *LD = dyn_cast<LabelDecl>(D))
2262 IdResolver.RemoveDecl(D);
2263 auto ShadowI = ShadowingDecls.find(D);
2264 if (ShadowI != ShadowingDecls.end()) {
2265 if (
const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) {
2266 addDiagWithPrev(D->
getLocation(), FD->getLocation(),
2267 PDiag(diag::warn_ctor_parm_shadows_field)
2268 << D << FD << FD->getParent());
2270 ShadowingDecls.erase(ShadowI);
2274 llvm::sort(DeclDiags,
2275 [](
const LocAndDiag &LHS,
const LocAndDiag &RHS) ->
bool {
2280 return LHS.Loc.getRawEncoding() < RHS.Loc.getRawEncoding();
2282 for (
const LocAndDiag &D : DeclDiags) {
2284 if (D.PreviousDeclLoc)
2285 Diag(*D.PreviousDeclLoc, diag::note_previous_declaration);
2304 bool DoTypoCorrection) {
2307 NamedDecl *IDecl = LookupSingleName(TUScope,
Id, IdLoc, LookupOrdinaryName);
2309 if (!IDecl && DoTypoCorrection) {
2315 TUScope,
nullptr, CCC, CTK_ErrorRecovery)) {
2316 diagnoseTypo(C, PDiag(diag::err_undef_interface_suggest) <<
Id);
2353 (S->getEntity() && S->getEntity()->isTransparentContext()) ||
2354 (S->isClassScope() && !getLangOpts().
CPlusPlus))
2371 return "ucontext.h";
2373 llvm_unreachable(
"unhandled error kind");
2384 Parent->addDecl(CLinkageDecl);
2390 getCurFPFeatures().isFPConstrained(),
2393 New->
addAttr(BuiltinAttr::CreateImplicit(Context,
ID));
2399 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2402 FT->getParamType(i),
nullptr,
SC_None,
nullptr);
2404 Params.push_back(parm);
2406 New->setParams(Params);
2409 AddKnownFunctionAttributes(New);
2418 Scope *S,
bool ForRedeclaration,
2420 LookupNecessaryTypesForBuiltin(S,
ID);
2425 if (!ForRedeclaration)
2437 Diag(Loc, diag::warn_implicit_decl_no_jmp_buf)
2444 Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
2450 if (!ForRedeclaration &&
2453 Diag(Loc, LangOpts.C99 ? diag::ext_implicit_lib_function_decl_c99
2454 : diag::ext_implicit_lib_function_decl)
2457 Diag(Loc, diag::note_include_header_or_declare)
2465 RegisterLocallyScopedExternCDecl(New, S);
2473 PushOnScopeChains(New, TUScope);
2474 CurContext = SavedContext;
2494 while (
Filter.hasNext()) {
2503 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2505 Decl->getUnderlyingType()))
2510 if (OldTD->getAnonDeclWithTypedefName(
true) &&
2511 Decl->getAnonDeclWithTypedefName())
2524 OldType = OldTypedef->getUnderlyingType();
2531 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2532 Diag(New->
getLocation(), diag::err_redefinition_variably_modified_typedef)
2540 if (OldType != NewType &&
2544 int Kind = isa<TypeAliasDecl>(Old) ? 1 : 0;
2546 <<
Kind << NewType << OldType;
2568 if (getLangOpts().ObjC) {
2570 switch (
TypeID->getLength()) {
2574 if (!
TypeID->isStr(
"id"))
2590 if (!
TypeID->isStr(
"Class"))
2597 if (!
TypeID->isStr(
"SEL"))
2624 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2625 auto *OldTag = OldTD->getAnonDeclWithTypedefName(
true);
2628 if (OldTag && NewTag &&
2629 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() &&
2630 !hasVisibleDefinition(OldTag, &Hidden)) {
2634 if (OldTD->isModed())
2636 OldTD->getUnderlyingType());
2641 makeMergedDefinitionVisible(Hidden);
2645 if (isa<EnumDecl>(NewTag)) {
2646 Scope *EnumScope = getNonFieldDeclScope(S);
2647 for (
auto *D : NewTag->decls()) {
2648 auto *ED = cast<EnumConstantDecl>(D);
2651 IdResolver.RemoveDecl(ED);
2652 ED->getLexicalDeclContext()->removeDecl(ED);
2660 if (isIncompatibleTypedef(Old, New))
2667 mergeDeclAttributes(New, Old);
2670 if (getLangOpts().MicrosoftExt)
2678 if (!isa<CXXRecordDecl>(CurContext))
2702 if (!isa<TypedefNameDecl>(Old))
2712 if (getLangOpts().Modules || getLangOpts().
C11)
2719 if (getDiagnostics().getSuppressSystemWarnings() &&
2734 const OwnershipAttr *OA = dyn_cast<OwnershipAttr>(A);
2735 const AnnotateAttr *Ann = dyn_cast<AnnotateAttr>(A);
2736 for (
const auto *i : D->
attrs())
2737 if (i->getKind() == A->
getKind()) {
2739 if (Ann->getAnnotation() == cast<AnnotateAttr>(i)->getAnnotation())
2744 if (OA && isa<OwnershipAttr>(i))
2745 return OA->getOwnKind() == cast<OwnershipAttr>(i)->getOwnKind();
2753 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
2754 return VD->isThisDeclarationADefinition();
2755 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
2756 return TD->isCompleteDefinition() || TD->isBeingDefined();
2767 AlignedAttr *OldAlignasAttr =
nullptr;
2768 AlignedAttr *OldStrictestAlignAttr =
nullptr;
2769 unsigned OldAlign = 0;
2777 if (I->isAlignmentDependent())
2783 unsigned Align = I->getAlignment(S.
Context);
2784 if (Align > OldAlign) {
2786 OldStrictestAlignAttr = I;
2791 AlignedAttr *NewAlignasAttr =
nullptr;
2792 unsigned NewAlign = 0;
2794 if (I->isAlignmentDependent())
2800 unsigned Align = I->getAlignment(S.
Context);
2801 if (Align > NewAlign)
2805 if (OldAlignasAttr && NewAlignasAttr && OldAlign != NewAlign) {
2813 if (OldAlign == 0 || NewAlign == 0) {
2815 if (
ValueDecl *VD = dyn_cast<ValueDecl>(New))
2826 if (OldAlign != NewAlign) {
2827 S.
Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch)
2830 S.
Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration);
2845 S.
Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration)
2849 bool AnyAdded =
false;
2852 if (OldAlign > NewAlign) {
2853 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.
Context);
2854 Clone->setInherited(
true);
2860 if (OldAlignasAttr && !NewAlignasAttr &&
2861 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) {
2862 AlignedAttr *Clone = OldAlignasAttr->clone(S.
Context);
2863 Clone->setInherited(
true);
2871 #define WANT_DECL_MERGE_LOGIC
2872 #include "clang/Sema/AttrParsedAttrImpl.inc"
2873 #undef WANT_DECL_MERGE_LOGIC
2880 if (!DiagnoseMutualExclusions(S, D,
Attr))
2891 if (
const auto *AA = dyn_cast<AvailabilityAttr>(
Attr))
2893 D, *AA, AA->getPlatform(), AA->
isImplicit(), AA->getIntroduced(),
2894 AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(),
2895 AA->getMessage(), AA->getStrict(), AA->getReplacement(), AMK,
2897 else if (
const auto *VA = dyn_cast<VisibilityAttr>(
Attr))
2899 else if (
const auto *VA = dyn_cast<TypeVisibilityAttr>(
Attr))
2901 else if (
const auto *ImportA = dyn_cast<DLLImportAttr>(
Attr))
2903 else if (
const auto *ExportA = dyn_cast<DLLExportAttr>(
Attr))
2905 else if (
const auto *EA = dyn_cast<ErrorAttr>(
Attr))
2907 else if (
const auto *FA = dyn_cast<FormatAttr>(
Attr))
2908 NewAttr = S.
mergeFormatAttr(D, *FA, FA->getType(), FA->getFormatIdx(),
2910 else if (
const auto *SA = dyn_cast<SectionAttr>(
Attr))
2912 else if (
const auto *CSA = dyn_cast<CodeSegAttr>(
Attr))
2914 else if (
const auto *IA = dyn_cast<MSInheritanceAttr>(
Attr))
2916 IA->getInheritanceModel());
2917 else if (
const auto *AA = dyn_cast<AlwaysInlineAttr>(
Attr))
2920 else if (S.
getLangOpts().CUDA && isa<FunctionDecl>(D) &&
2921 (isa<CUDAHostAttr>(
Attr) || isa<CUDADeviceAttr>(
Attr) ||
2922 isa<CUDAGlobalAttr>(
Attr))) {
2926 }
else if (
const auto *MA = dyn_cast<MinSizeAttr>(
Attr))
2928 else if (
const auto *SNA = dyn_cast<SwiftNameAttr>(
Attr))
2930 else if (
const auto *OA = dyn_cast<OptimizeNoneAttr>(
Attr))
2932 else if (
const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(
Attr))
2934 else if (isa<AlignedAttr>(
Attr))
2938 else if ((isa<DeprecatedAttr>(
Attr) || isa<UnavailableAttr>(
Attr)) &&
2943 else if (
const auto *UA = dyn_cast<UuidAttr>(
Attr))
2944 NewAttr = S.
mergeUuidAttr(D, *UA, UA->getGuid(), UA->getGuidDecl());
2945 else if (
const auto *IMA = dyn_cast<WebAssemblyImportModuleAttr>(
Attr))
2947 else if (
const auto *INA = dyn_cast<WebAssemblyImportNameAttr>(
Attr))
2949 else if (
const auto *TCBA = dyn_cast<EnforceTCBAttr>(
Attr))
2951 else if (
const auto *TCBLA = dyn_cast<EnforceTCBLeafAttr>(
Attr))
2953 else if (
const auto *BTFA = dyn_cast<BTFDeclTagAttr>(
Attr))
2955 else if (
const auto *NT = dyn_cast<HLSLNumThreadsAttr>(
Attr))
2958 else if (
const auto *SA = dyn_cast<HLSLShaderAttr>(
Attr))
2966 if (isa<MSInheritanceAttr>(NewAttr))
2975 if (
const TagDecl *TD = dyn_cast<TagDecl>(D))
2976 return TD->getDefinition();
2977 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2983 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
2985 if (FD->isDefined(Def,
true))
2992 for (
const auto *Attribute : D->
attrs())
2993 if (Attribute->getKind() ==
Kind)
3005 if (!Def || Def == New)
3009 for (
unsigned I = 0, E = NewAttributes.size(); I != E;) {
3010 const Attr *NewAttribute = NewAttributes[I];
3012 if (isa<AliasAttr>(NewAttribute) || isa<IFuncAttr>(NewAttribute)) {
3019 NewAttributes.erase(NewAttributes.begin() + I);
3024 VarDecl *VD = cast<VarDecl>(New);
3025 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() ==
3027 ? diag::err_alias_after_tentative
3028 : diag::err_redefinition;
3030 if (
Diag == diag::err_redefinition)
3040 if (
const VarDecl *VD = dyn_cast<VarDecl>(Def)) {
3053 if (isa<C11NoReturnAttr>(NewAttribute)) {
3057 }
else if (isa<UuidAttr>(NewAttribute)) {
3061 }
else if (
const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) {
3062 if (AA->isAlignas()) {
3073 S.
Diag(NewAttribute->
getLocation(), diag::note_alignas_on_declaration)
3075 NewAttributes.erase(NewAttributes.begin() + I);
3079 }
else if (isa<LoaderUninitializedAttr>(NewAttribute)) {
3085 diag::err_loader_uninitialized_redeclaration);
3087 NewAttributes.erase(NewAttributes.begin() + I);
3091 }
else if (isa<SelectAnyAttr>(NewAttribute) &&
3092 cast<VarDecl>(New)->isInline() &&
3093 !cast<VarDecl>(New)->isInlineSpecified()) {
3100 }
else if (isa<OMPDeclareVariantAttr>(NewAttribute)) {
3108 diag::warn_attribute_precede_definition);
3110 NewAttributes.erase(NewAttributes.begin() + I);
3116 const ConstInitAttr *CIAttr,
3117 bool AttrBeforeInit) {
3128 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3130 InsertLoc, {tok::l_square, tok::l_square,
3131 S.PP.getIdentifierInfo(
"clang"), tok::coloncolon,
3132 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3133 tok::r_square, tok::r_square}));
3134 if (SuitableSpelling.empty())
3136 InsertLoc, {tok::kw___attribute, tok::l_paren, tok::r_paren,
3137 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3138 tok::r_paren, tok::r_paren}));
3139 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus20)
3140 SuitableSpelling =
"constinit";
3141 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3142 SuitableSpelling =
"[[clang::require_constant_initialization]]";
3143 if (SuitableSpelling.empty())
3144 SuitableSpelling =
"__attribute__((require_constant_initialization))";
3145 SuitableSpelling +=
" ";
3147 if (AttrBeforeInit) {
3150 assert(CIAttr->isConstinit() &&
"should not diagnose this for attribute");
3153 S.
Diag(CIAttr->getLocation(), diag::note_constinit_specified_here);
3157 S.
Diag(CIAttr->getLocation(),
3158 CIAttr->isConstinit() ? diag::err_constinit_added_too_late
3159 : diag::warn_require_const_init_added_too_late)
3162 << CIAttr->isConstinit()
3171 UsedAttr *NewAttr = OldAttr->clone(Context);
3172 NewAttr->setInherited(
true);
3176 RetainAttr *NewAttr = OldAttr->clone(Context);
3177 NewAttr->setInherited(
true);
3187 const auto *OldConstInit = Old->
getAttr<ConstInitAttr>();
3188 const auto *NewConstInit = New->
getAttr<ConstInitAttr>();
3189 if (
bool(OldConstInit) !=
bool(NewConstInit)) {
3190 const auto *OldVD = cast<VarDecl>(Old);
3191 auto *NewVD = cast<VarDecl>(New);
3197 (NewVD->hasInit() || NewVD->isThisDeclarationADefinition()))
3200 if (InitDecl == NewVD) {
3204 if (OldConstInit && OldConstInit->isConstinit())
3207 }
else if (NewConstInit) {
3211 if (InitDecl && InitDecl != NewVD) {
3214 NewVD->dropAttr<ConstInitAttr>();
3222 if (AsmLabelAttr *NewA = New->
getAttr<AsmLabelAttr>()) {
3223 if (AsmLabelAttr *OldA = Old->
getAttr<AsmLabelAttr>()) {
3224 if (!OldA->isEquivalent(NewA)) {
3227 Diag(OldA->getLocation(), diag::note_previous_declaration);
3229 }
else if (Old->
isUsed()) {
3233 << isa<FunctionDecl>(Old) << New->
getAttr<AsmLabelAttr>()->
getRange();
3238 if (
const auto *NewAbiTagAttr = New->
getAttr<AbiTagAttr>()) {
3239 if (
const auto *OldAbiTagAttr = Old->
getAttr<AbiTagAttr>()) {
3240 for (
const auto &NewTag : NewAbiTagAttr->tags()) {
3241 if (!llvm::is_contained(OldAbiTagAttr->tags(), NewTag)) {
3242 Diag(NewAbiTagAttr->getLocation(),
3243 diag::err_new_abi_tag_on_redeclaration)
3245 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
3249 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
3255 if (New->
hasAttr<SectionAttr>() && !Old->
hasAttr<SectionAttr>()) {
3256 if (
auto *VD = dyn_cast<VarDecl>(New)) {
3258 Diag(New->
getLocation(), diag::warn_attribute_section_on_redeclaration);
3265 const auto *NewCSA = New->
getAttr<CodeSegAttr>();
3266 if (NewCSA && !Old->
hasAttr<CodeSegAttr>() &&
3267 !NewCSA->isImplicit() && isa<CXXMethodDecl>(New)) {
3285 if (isa<DeprecatedAttr>(I) ||
3286 isa<UnavailableAttr>(I) ||
3287 isa<AvailabilityAttr>(I)) {
3292 case AMK_Redeclaration:
3294 case AMK_ProtocolImplementation:
3295 case AMK_OptionalProtocolImplementation:
3302 if (isa<UsedAttr>(I) || isa<RetainAttr>(I))
3324 const CarriesDependencyAttr *CDA = newDecl->
getAttr<CarriesDependencyAttr>();
3325 if (CDA && !oldDecl->
hasAttr<CarriesDependencyAttr>()) {
3326 S.
Diag(CDA->getLocation(),
3327 diag::err_carries_dependency_missing_on_first_decl) << 1;
3335 diag::note_carries_dependency_missing_first_decl) << 1;
3341 bool foundAny = newDecl->
hasAttrs();
3350 cast<InheritableParamAttr>(I->clone(S.
Context));
3363 auto NoSizeInfo = [&Ctx](
QualType Ty) {
3364 if (Ty->isIncompleteArrayType() || Ty->isPointerType())
3367 return VAT->getSizeModifier() == ArrayType::ArraySizeModifier::Star;
3372 if (NoSizeInfo(Old) && NoSizeInfo(New))
3379 if ((OldVAT->getSizeModifier() == ArrayType::ArraySizeModifier::Star) ^
3380 (NewVAT->getSizeModifier() == ArrayType::ArraySizeModifier::Star))
3404 if (*Oldnullability != *Newnullability) {
3405 S.
Diag(NewParam->
getLocation(), diag::warn_mismatched_nullability_attr)
3424 const auto *OldParamDT = dyn_cast<DecayedType>(OldParam->
getType());
3425 const auto *NewParamDT = dyn_cast<DecayedType>(NewParam->
getType());
3426 if (OldParamDT && NewParamDT &&
3427 OldParamDT->getPointeeType() == NewParamDT->getPointeeType()) {
3428 QualType OldParamOT = OldParamDT->getOriginalType();
3429 QualType NewParamOT = NewParamDT->getOriginalType();
3432 << NewParam << NewParamOT;
3443 struct GNUCompatibleParamWarning {
3453 template <
typename T>
3454 static std::pair<diag::kind, SourceLocation>
3458 if (Old->isThisDeclarationADefinition())
3459 PrevDiag = diag::note_previous_definition;
3460 else if (Old->isImplicit()) {
3461 PrevDiag = diag::note_previous_implicit_declaration;
3462 if (
const auto *FD = dyn_cast<FunctionDecl>(Old)) {
3463 if (FD->getBuiltinID())
3464 PrevDiag = diag::note_previous_builtin_declaration;
3467 OldLocation = New->getLocation();
3469 PrevDiag = diag::note_previous_declaration;
3470 return std::make_pair(PrevDiag, OldLocation);
3478 return ((FD->
hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) &&
3479 !LangOpts.CPlusPlus &&
3491 template <
typename T>
3505 template<
typename T>
static bool isExternC(T *D) {
return D->isExternC(); }
3512 template<
typename ExpectedDecl>
3534 !Old->getDeclContext()->getRedeclContext()->Equals(
3535 New->getDeclContext()->getRedeclContext()) &&
3540 S.
Diag(New->getLocation(), diag::err_using_decl_conflict_reverse);
3553 const auto *AttrA = A->
getAttr<PassObjectSizeAttr>();
3554 const auto *AttrB = B->
getAttr<PassObjectSizeAttr>();
3557 return AttrA && AttrB && AttrA->getType() == AttrB->getType() &&
3558 AttrA->isDynamic() == AttrB->isDynamic();
3561 return std::equal(A->param_begin(), A->param_end(), B->
param_begin(), AttrEq);
3584 if (NamedDC->Equals(SemaDC))
3587 assert((NamedDC->InEnclosingNamespaceSetOf(SemaDC) ||
3589 "unexpected context for redeclaration");
3600 if (
auto *FD = dyn_cast<FunctionDecl>(NewD))
3601 FixSemaDC(FD->getDescribedFunctionTemplate());
3602 else if (
auto *VD = dyn_cast<VarDecl>(NewD))
3603 FixSemaDC(VD->getDescribedVarTemplate());
3618 bool MergeTypeWithOld,
bool NewDeclIsDefn) {
3625 Diag(Shadow->getTargetDecl()->getLocation(),
3626 diag::note_using_decl_target);
3627 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
3636 if (checkUsingShadowRedecl<FunctionTemplateDecl>(*
this, Shadow,
3639 OldD = Old = cast<FunctionTemplateDecl>(Shadow->getTargetDecl())
3642 if (checkUsingShadowRedecl<FunctionDecl>(*
this, Shadow, New))
3644 OldD = Old = cast<FunctionDecl>(Shadow->getTargetDecl());
3663 if (!getASTContext().canBuiltinBeRedeclared(Old)) {
3672 std::tie(PrevDiag, OldLocation) =
3679 if (!isa<CXXMethodDecl>(New) && !isa<CXXMethodDecl>(Old) &&
3684 if (getLangOpts().MicrosoftExt) {
3686 Diag(OldLocation, PrevDiag);
3689 Diag(OldLocation, PrevDiag);
3694 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
3695 if (!Old->
hasAttr<InternalLinkageAttr>()) {
3699 New->
dropAttr<InternalLinkageAttr>();
3702 if (
auto *EA = New->
getAttr<ErrorAttr>()) {
3703 if (!Old->
hasAttr<ErrorAttr>()) {
3704 Diag(EA->getLocation(), diag::err_attribute_missing_on_first_decl) << EA;
3710 if (CheckRedeclarationInModule(New, Old))
3713 if (!getLangOpts().CPlusPlus) {
3714 bool OldOvl = Old->
hasAttr<OverloadableAttr>();
3725 const Decl *DiagOld = Old;
3727 auto OldIter = llvm::find_if(Old->
redecls(), [](
const Decl *D) {
3728 const auto *A = D->getAttr<OverloadableAttr>();
3729 return A && !A->isImplicit();
3733 DiagOld = OldIter == Old->
redecls_end() ? nullptr : *OldIter;
3738 diag::note_attribute_overloadable_prev_overload)
3742 New->
addAttr(OverloadableAttr::CreateImplicit(Context));
3763 const FunctionType *OldType = cast<FunctionType>(OldQType);
3764 const FunctionType *NewType = cast<FunctionType>(NewQType);
3767 bool RequiresAdjustment =
false;
3769 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC()) {
3774 bool NewCCExplicit = getCallingConvAttributedType(New->
getType());
3775 if (!NewCCExplicit) {
3779 RequiresAdjustment =
true;
3789 << (
int)CallingConventionIgnoredReason::BuiltinFunction;
3791 RequiresAdjustment =
true;
3794 bool FirstCCExplicit = getCallingConvAttributedType(
First->getType());
3798 << (!FirstCCExplicit ?
"" :
3802 Diag(
First->getLocation(), diag::note_previous_declaration);
3810 RequiresAdjustment =
true;
3820 Diag(OldLocation, diag::note_previous_declaration);
3825 RequiresAdjustment =
true;
3832 <<
"'ns_returns_retained'";
3833 Diag(OldLocation, diag::note_previous_declaration);
3838 RequiresAdjustment =
true;
3844 AnyX86NoCallerSavedRegistersAttr *
Attr =
3845 New->
getAttr<AnyX86NoCallerSavedRegistersAttr>();
3847 Diag(OldLocation, diag::note_previous_declaration);
3852 RequiresAdjustment =
true;
3855 if (RequiresAdjustment) {
3865 !New->
hasAttr<GNUInlineAttr>() &&
3866 !getLangOpts().GNUInline &&
3874 if (New->
hasAttr<GNUInlineAttr>() &&
3885 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3900 if (CheckEquivalentExceptionSpec(Old, New))
3912 if (!Context.
hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) &&
3913 canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType,
3914 OldDeclaredReturnType)) {
3922 Diag(New->
getLocation(), diag::err_member_def_does_not_match_ret_type)
3927 Diag(OldLocation, PrevDiag) << Old << Old->
getType()
3936 QualType NewReturnType = cast<FunctionType>(NewQType)->getReturnType();
3937 if (OldReturnType != NewReturnType) {
3953 const CXXMethodDecl *OldMethod = dyn_cast<CXXMethodDecl>(Old);
3955 if (OldMethod && NewMethod) {
3962 bool IsClassScopeExplicitSpecialization =
3968 !IsClassScopeExplicitSpecialization) {
3974 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3982 if (!inTemplateInstantiation()) {
3984 if (isa<CXXConstructorDecl>(OldMethod))
3985 NewDiag = diag::err_constructor_redeclared;
3986 else if (isa<CXXDestructorDecl>(NewMethod))
3987 NewDiag = diag::err_destructor_redeclared;
3988 else if (isa<CXXConversionDecl>(NewMethod))
3989 NewDiag = diag::err_conv_function_redeclared;
3991 NewDiag = diag::err_member_redeclared;
3995 Diag(New->
getLocation(), diag::err_member_redeclared_in_instantiation)
3998 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4011 diag::err_definition_of_implicitly_declared_member)
4012 << New << getSpecialMember(OldMethod);
4017 diag::err_definition_of_explicitly_defaulted_member)
4018 << getSpecialMember(OldMethod);
4027 if (
const auto *NRA = New->
getAttr<CXX11NoReturnAttr>())
4028 if (!Old->
hasAttr<CXX11NoReturnAttr>()) {
4029 Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl)
4038 const CarriesDependencyAttr *CDA = New->
getAttr<CarriesDependencyAttr>();
4039 if (CDA && !Old->
hasAttr<CarriesDependencyAttr>()) {
4040 Diag(CDA->getLocation(),
4041 diag::err_carries_dependency_missing_on_first_decl) << 0;
4043 diag::note_carries_dependency_missing_first_decl) << 0;
4052 QualType OldQTypeForComparison = OldQType;
4057 OldQTypeForComparison =
QualType(OldTypeForComparison, 0);
4072 Diag(OldLocation, PrevDiag);
4074 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4075 Diag(OldLocation, PrevDiag);
4086 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
4091 if (!canFullyTypeCheckRedeclaration(New, Old, NewQType, OldQType))
4146 bool IsWithoutProtoADef =
false, IsWithProtoADef =
false;
4147 if (WithoutProto == New)
4148 IsWithoutProtoADef = NewDeclIsDefn;
4150 IsWithProtoADef = NewDeclIsDefn;
4152 diag::warn_non_prototype_changes_behavior)
4153 << IsWithoutProtoADef << (WithoutProto->
getNumParams() ? 0 : 1)
4154 << (WithoutProto == Old) << IsWithProtoADef;
4164 !IsWithoutProtoADef)
4174 if (MergeTypeWithOld && isa<FunctionNoProtoType>(NewFuncType) &&
4175 (OldProto = dyn_cast<FunctionProtoType>(OldFuncType))) {
4178 assert(!OldProto->hasExceptionSpec() &&
"Exception spec in C");
4180 OldProto->getParamTypes(),
4181 OldProto->getExtProtoInfo());
4187 for (
const auto &ParamType : OldProto->param_types()) {
4190 ParamType,
nullptr,
SC_None,
nullptr);
4193 Params.push_back(Param);
4196 New->setParams(Params);
4199 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
4232 NewProto->getReturnType());
4233 bool LooseCompatible = !MergedReturn.
isNull();
4235 LooseCompatible && Idx !=
End; ++Idx) {
4239 NewProto->getParamType(Idx))) {
4240 ArgTypes.push_back(NewParm->
getType());
4244 GNUCompatibleParamWarning Warn = { OldParm, NewParm,
4245 NewProto->getParamType(Idx) };
4246 Warnings.push_back(Warn);
4247 ArgTypes.push_back(NewParm->
getType());
4249 LooseCompatible =
false;
4252 if (LooseCompatible) {
4253 for (
unsigned Warn = 0; Warn < Warnings.size(); ++Warn) {
4254 Diag(Warnings[Warn].NewParm->getLocation(),
4255 diag::ext_param_promoted_not_compatible_with_prototype)
4256 << Warnings[Warn].PromotedType
4257 << Warnings[Warn].OldParm->getType();
4258 if (Warnings[Warn].OldParm->getLocation().isValid())
4259 Diag(Warnings[Warn].OldParm->getLocation(),
4260 diag::note_previous_declaration);
4263 if (MergeTypeWithOld)
4266 return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
4283 Diag(OldLocation, diag::note_previous_builtin_declaration)
4288 PrevDiag = diag::note_previous_builtin_declaration;
4292 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4306 Scope *S,
bool MergeTypeWithOld) {
4308 mergeDeclAttributes(New, Old);
4321 for (
unsigned i = 0, e = New->
getNumParams(); i != e; ++i) {
4329 return MergeCXXFunctionDecl(New, Old, S);
4335 if (!Merged.isNull() && MergeTypeWithOld)
4346 ? (oldMethod->
isOptional() ? AMK_OptionalProtocolImplementation
4347 : AMK_ProtocolImplementation)
4348 : isa<ObjCImplDecl>(newMethod->
getDeclContext()) ? AMK_Redeclaration
4351 mergeDeclAttributes(newMethod, oldMethod, MergeKind);
4358 ni != ne && oi != oe; ++ni, ++oi)
4361 CheckObjCMethodOverride(newMethod, oldMethod);
4368 ? diag::err_redefinition_different_type
4369 : diag::err_redeclaration_different_type)
4374 std::tie(PrevDiag, OldLocation)
4376 S.
Diag(OldLocation, PrevDiag);
4388 bool MergeTypeWithOld) {
4399 return MergeVarDeclExceptionSpecs(New, Old);
4416 QualType PrevVDTy = PrevVD->getType();
4470 if (MergeTypeWithOld)
4516 if (!shouldLinkPossiblyHiddenDecl(
Previous, New))
4526 OldTemplate = dyn_cast<VarTemplateDecl>(
Previous.getFoundDecl());
4530 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4531 if (checkUsingShadowRedecl<VarTemplateDecl>(*
this, Shadow, NewTemplate))
4534 Old = dyn_cast<VarDecl>(
Previous.getFoundDecl());
4537 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4538 if (checkUsingShadowRedecl<VarDecl>(*
this, Shadow, New))
4545 notePreviousDefinition(
Previous.getRepresentativeDecl(),
4558 true, TPL_TemplateMatch))
4572 mergeDeclAttributes(New, Old);
4575 if (New->
hasAttr<WeakImportAttr>() &&
4577 !Old->
hasAttr<WeakImportAttr>()) {
4584 if (
const auto *ILA = New->
getAttr<InternalLinkageAttr>())
4585 if (!Old->
hasAttr<InternalLinkageAttr>()) {
4589 New->
dropAttr<InternalLinkageAttr>();
4594 if (MostRecent != Old) {
4595 MergeVarDeclTypes(New, MostRecent,
4607 std::tie(PrevDiag, OldLocation) =
4614 if (getLangOpts().MicrosoftExt) {
4617 Diag(OldLocation, PrevDiag);
4621 Diag(OldLocation, PrevDiag);
4640 Diag(OldLocation, PrevDiag);
4648 Diag(OldLocation, PrevDiag);
4654 Diag(OldLocation, PrevDiag);
4658 if (CheckRedeclarationInModule(New, Old))
4670 Diag(OldLocation, PrevDiag);
4680 Diag(Def->getLocation(), diag::note_previous_definition);
4694 Diag(OldLocation, PrevDiag);
4697 Diag(OldLocation, PrevDiag);
4705 Diag(OldLocation, PrevDiag);
4715 diag::warn_deprecated_redundant_constexpr_static_def);
4718 if (Def && checkVarDeclRedefinition(Def, New))
4724 Diag(New->
getLocation(), diag::err_different_language_linkage) << New;
4725 Diag(OldLocation, PrevDiag);
4754 auto &HSI = PP.getHeaderSearchInfo();
4755 StringRef HdrFilename =
4758 auto noteFromModuleOrInclude = [&](
Module *Mod,
4764 if (IncLoc.isValid()) {
4766 Diag(IncLoc, diag::note_redefinition_modules_same_file)
4772 Diag(IncLoc, diag::note_redefinition_include_same_file)
4773 << HdrFilename.str();
4783 if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
4788 EmittedDiag |= noteFromModuleOrInclude(getCurrentModule(), NewIncLoc);
4791 if (FOld && !HSI.isFileMultipleIncludeGuarded(FOld))
4806 if (!hasVisibleDefinition(Old) &&
4809 isa<VarTemplateSpecializationDecl>(New) ||
4819 makeMergedDefinitionVisible(OldTD);
4820 makeMergedDefinitionVisible(Old);
4836 return ParsedFreeStandingDeclSpec(
4848 ? S->getMSCurManglingNumber()
4849 : S->getMSLastManglingNumber();
4856 if (isa<CXXRecordDecl>(Tag->
getParent())) {
4871 Decl *ManglingContextDecl;
4872 std::tie(MCtx, ManglingContextDecl) =
4882 struct NonCLikeKind {
4894 explicit operator bool() {
return Kind != None; }
4909 return {NonCLikeKind::BaseClass,
4912 bool Invalid =
false;
4921 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
4922 if (FD->hasInClassInitializer()) {
4923 auto *Init = FD->getInClassInitializer();
4924 return {NonCLikeKind::DefaultMemberInit,
4932 if (isa<FriendDecl>(D))
4937 if (isa<StaticAssertDecl>(D) || isa<IndirectFieldDecl>(D) ||
4940 auto *MemberRD = dyn_cast<CXXRecordDecl>(D);
4948 if (MemberRD->isLambda())
4949 return {NonCLikeKind::Lambda, MemberRD->getSourceRange()};
4953 if (MemberRD->isThisDeclarationADefinition()) {
4989 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(TagFromDeclSpec);
4993 if (NonCLike || ChangesLinkage) {
4997 unsigned DiagID = diag::ext_non_c_like_anon_struct_in_typedef;
4998 if (ChangesLinkage) {
5001 DiagID = diag::err_typedef_changes_linkage;
5003 DiagID = diag::err_non_c_like_anon_struct_in_typedef;
5009 TextToInsert +=
' ';
5012 Diag(FixitLoc, DiagID)
5013 << isa<TypeAliasDecl>(NewTD)
5016 Diag(NonCLike.Range.getBegin(), diag::note_non_c_like_anon_struct)
5017 << NonCLike.Kind - 1 << NonCLike.Range;
5020 << NewTD << isa<TypeAliasDecl>(NewTD);
5043 llvm_unreachable(
"unexpected type specifier");
5054 bool IsExplicitInstantiation,
5056 Decl *TagD =
nullptr;
5071 if (isa<TagDecl>(TagD))
5072 Tag = cast<TagDecl>(TagD);
5074 Tag = CTD->getTemplatedDecl();
5078 handleTagNumbering(Tag, S);
5089 diag::err_typecheck_invalid_restrict_not_pointer_noarg)
5095 << getLangOpts().CPlusPlus17;
5113 DiagnoseFunctionSpecifiers(DS);
5120 return ActOnFriendTypeDecl(S, DS, TemplateParams);
5124 bool IsExplicitSpecialization =
5125 !TemplateParams.empty() && TemplateParams.back()->size() == 0;
5127 !IsExplicitInstantiation && !IsExplicitSpecialization &&
5128 !isa<ClassTemplatePartialSpecializationDecl>(Tag)) {
5137 Diag(SS.
getBeginLoc(), diag::err_standalone_class_nested_name_specifier)
5143 bool DeclaresAnything =
true;
5146 if (
RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag)) {
5147 if (!Record->getDeclName() && Record->isCompleteDefinition() &&
5150 Record->getDeclContext()->isRecord()) {
5158 if (CurContext->isFunctionOrMethod())
5159 AnonRecord = Record;
5160 return BuildAnonymousStructOrUnion(S, DS, AS, Record,
5164 DeclaresAnything =
false;
5174 if (!getLangOpts().
CPlusPlus && CurContext->isRecord() &&
5187 Record = dyn_cast<RecordDecl>(Tag);
5190 Record = RT->getDecl();
5192 Record = UT->getDecl();
5194 if (Record && getLangOpts().MicrosoftExt) {
5197 return BuildMicrosoftCAnonymousStruct(S, DS, Record);
5200 DeclaresAnything =
false;
5211 if (
EnumDecl *Enum = dyn_cast_or_null<EnumDecl>(Tag))
5212 if (Enum->enumerator_begin() == Enum->enumerator_end() &&
5213 !Enum->getIdentifier() && !Enum->isInvalidDecl())
5214 DeclaresAnything =
false;
5222 DeclaresAnything =
false;
5231 ActOnDocumentableDecl(TagD);
5241 if (!DeclaresAnything) {
5244 Diag(DS.
getBeginLoc(), (IsExplicitInstantiation || !TemplateParams.empty())
5245 ? diag::err_no_declarators
5246 : diag::ext_no_declarators)
5259 unsigned DiagID = diag::warn_standalone_specifier;
5261 DiagID = diag::ext_standalone_specifier;
5302 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
5305 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
5329 assert(PrevDecl &&
"Expected a non-null Decl");
5334 SemaRef.
Diag(NameLoc, diag::err_anonymous_record_member_redecl)
5336 SemaRef.
Diag(PrevDecl->
getLocation(), diag::note_previous_declaration);
5361 bool Invalid =
false;
5364 for (
auto *D : AnonRecord->
decls()) {
5365 if ((isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) &&
5366 cast<NamedDecl>(D)->getDeclName()) {
5382 unsigned OldChainingSize = Chaining.size();
5384 Chaining.append(IF->chain_begin(), IF->chain_end());
5386 Chaining.push_back(VD);
5388 assert(Chaining.size() >= 2);
5391 for (
unsigned i = 0; i < Chaining.size(); i++)
5392 NamedChain[i] = Chaining[i];
5396 VD->
getType(), {NamedChain, Chaining.size()});
5408 Chaining.resize(OldChainingSize);
5423 "Parser allowed 'typedef' as storage class VarDecl.");
5424 switch (StorageClassSpec) {
5438 llvm_unreachable(
"unknown storage class specifier");
5444 for (
const auto *I : Record->
decls()) {
5445 const auto *FD = dyn_cast<FieldDecl>(I);
5446 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
5447 FD = IFD->getAnonField();
5448 if (FD && FD->hasInClassInitializer())
5449 return FD->getLocation();
5452 llvm_unreachable(
"couldn't find in-class initializer");
5457 if (!
Parent->isUnion() || !
Parent->hasInClassInitializer())
5460 S.
Diag(DefaultInitLoc, diag::err_multiple_mem_union_initialization);
5466 if (!
Parent->isUnion() || !
Parent->hasInClassInitializer())
5487 else if (!Record->
isUnion() && !getLangOpts().
C11)
5492 bool Invalid =
false;
5494 const char *PrevSpec =
nullptr;
5505 !cast<NamespaceDecl>(OwnerScope)->isAnonymousNamespace()))) {
5511 PrevSpec, DiagID, Policy);
5517 isa<RecordDecl>(Owner)) {
5519 diag::err_anonymous_union_with_storage_spec)
5533 << Record->
isUnion() <<
"const"
5537 diag::ext_anonymous_struct_union_qualified)
5538 << Record->
isUnion() <<
"volatile"
5542 diag::ext_anonymous_struct_union_qualified)
5543 << Record->
isUnion() <<
"restrict"
5547 diag::ext_anonymous_struct_union_qualified)
5548 << Record->
isUnion() <<
"_Atomic"
5552 diag::ext_anonymous_struct_union_qualified)
5553 << Record->
isUnion() <<
"__unaligned"
5563 for (
auto *Mem : Record->
decls()) {
5565 if (Mem->isInvalidDecl())
5568 if (
auto *FD = dyn_cast<FieldDecl>(Mem)) {
5572 assert(FD->getAccess() !=
AS_none);
5574 Diag(FD->getLocation(), diag::err_anonymous_record_nonpublic_member)
5584 if (CheckNontrivialField(FD))
5586 }
else if (Mem->isImplicit()) {
5588 }
else if (isa<TagDecl>(Mem) && Mem->getDeclContext() != Record) {
5593 }
else if (
auto *MemRecord = dyn_cast<RecordDecl>(Mem)) {
5594 if (!MemRecord->isAnonymousStructOrUnion() &&
5595 MemRecord->getDeclName()) {
5597 if (getLangOpts().MicrosoftExt)
5598 Diag(MemRecord->getLocation(), diag::ext_anonymous_record_with_type)
5602 Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type)
5610 Diag(MemRecord->getLocation(),
5611 diag::ext_anonymous_record_with_anonymous_type)
5614 }
else if (isa<AccessSpecDecl>(Mem)) {
5616 }
else if (isa<StaticAssertDecl>(Mem)) {
5621 unsigned DK = diag::err_anonymous_record_bad_member;
5622 if (isa<TypeDecl>(Mem))
5623 DK = diag::err_anonymous_record_with_type;
5624 else if (isa<FunctionDecl>(Mem))
5625 DK = diag::err_anonymous_record_with_function;
5626 else if (isa<VarDecl>(Mem))
5627 DK = diag::err_anonymous_record_with_static;
5630 if (getLangOpts().MicrosoftExt &&
5631 DK == diag::err_anonymous_record_with_type)
5632 Diag(Mem->getLocation(), diag::ext_anonymous_record_with_type)
5635 Diag(Mem->getLocation(), DK) << Record->
isUnion();
5644 if (cast<CXXRecordDecl>(Record)->hasInClassInitializer() &&
5647 cast<CXXRecordDecl>(Record));
5652 << getLangOpts().CPlusPlus;
5671 assert(TInfo &&
"couldn't build declarator info for anonymous struct/union");
5675 if (
RecordDecl *OwningClass = dyn_cast<RecordDecl>(Owner)) {
5682 ProcessDeclAttributes(S, Anon, Dc);
5685 FieldCollector->Add(cast<FieldDecl>(Anon));
5706 ActOnUninitializedDecl(Anon);
5722 Chain.push_back(Anon);
5727 if (
VarDecl *NewVD = dyn_cast<VarDecl>(Anon)) {
5728 if (getLangOpts().
CPlusPlus && NewVD->isStaticLocal()) {
5730 Decl *ManglingContextDecl;
5731 std::tie(MCtx, ManglingContextDecl) =
5732 getCurrentMangleNumberContext(NewVD->getDeclContext());
5763 assert(Record &&
"expected a record!");
5768 assert(TInfo &&
"couldn't build declarator info for anonymous struct");
5770 auto *ParentDecl = cast<RecordDecl>(CurContext);
5776 nullptr, RecTy, TInfo,
5782 CurContext->addDecl(Anon);
5788 Chain.push_back(Anon);
5791 if (RequireCompleteSizedType(Anon->
getLocation(), RecTy,
5792 diag::err_field_incomplete_or_sizeless) ||
5796 ParentDecl->setInvalidDecl();
5805 return GetNameFromUnqualifiedId(D.
getName());
5812 NameInfo.
setLoc(Name.StartLocation);
5814 switch (Name.getKind()) {
5818 NameInfo.
setName(Name.Identifier);
5834 if (!Template || !isa<ClassTemplateDecl>(Template)) {
5835 Diag(Name.StartLocation,
5836 diag::err_deduction_guide_name_not_class_template)
5837 << (
int)getTemplateNameKindForDiagnostics(TN) << TN;
5839 Diag(Template->getLocation(), diag::note_template_decl_here);
5850 Name.OperatorFunctionId.Operator));
5852 Name.OperatorFunctionId.SymbolLocations[0], Name.EndLocation));
5863 QualType Ty = GetTypeFromParser(Name.ConversionFunctionId, &TInfo);
5874 QualType Ty = GetTypeFromParser(Name.ConstructorName, &TInfo);
5887 CXXRecordDecl *CurClass = dyn_cast<CXXRecordDecl>(CurContext);
5888 if (!CurClass || CurClass->
getIdentifier() != Name.TemplateId->Name)
5907 QualType Ty = GetTypeFromParser(Name.DestructorName, &TInfo);
5924 llvm_unreachable(
"Unknown name kind");
5950 if (Declaration->param_size() != Definition->param_size())
5952 for (
unsigned Idx = 0; Idx < Declaration->param_size(); ++Idx) {
5953 QualType DeclParamTy = Declaration->getParamDecl(Idx)->getType();
5954 QualType DefParamTy = Definition->getParamDecl(Idx)->getType();
5966 (DeclTyName && DeclTyName == DefTyName))
5967 Params.push_back(Idx);
5994 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case DeclSpec::TST_##Trait:
5995 #include "clang/Basic/TransformTypeTraits.def"
6010 if (!TSI)
return true;
6023 if (Result.isInvalid())
return true;
6068 << D << static_cast<int>(Status);
6078 if (LangOpts.OpenMP && isInOpenMPDeclareVariantScope())
6079 if (getOMPTraitInfoForSurroundingScope()->isExtensionActive(llvm::omp::TraitProperty::
6080 implementation_extension_bind_to_declaration))
6081 ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
6086 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() &&
6091 ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(Dcl, Bases);
6109 Record = dyn_cast<CXXRecordDecl>(Record->
getParent());
6111 Diag(NameInfo.
getLoc(), diag::err_member_name_of_class) << Name;
6138 while (isa<LinkageSpecDecl>(Cur) || isa<CapturedDecl>(Cur))
6152 Diag(Loc, LangOpts.MicrosoftExt ? diag::warn_member_extra_qualification
6153 : diag::err_member_extra_qualification)
6157 Diag(Loc, diag::warn_namespace_member_extra_qualification) << Name;
6165 if (!Cur->
Encloses(DC) && !IsTemplateId) {
6167 Diag(Loc, diag::err_member_qualification)
6169 else if (isa<TranslationUnitDecl>(DC))
6170 Diag(Loc, diag::err_invalid_declarator_global_scope)
6172 else if (isa<FunctionDecl>(Cur))
6173 Diag(Loc, diag::err_invalid_declarator_in_function)
6175 else if (isa<BlockDecl>(Cur))
6176 Diag(Loc, diag::err_invalid_declarator_in_block)
6178 else if (isa<ExportDecl>(Cur)) {
6179 if (!isa<NamespaceDecl>(DC))
6180 Diag(Loc, diag::err_export_non_namespace_scope_name)
6187 Diag(Loc, diag::err_invalid_declarator_scope)
6188 << Name << cast<NamedDecl>(Cur) << cast<NamedDecl>(DC) << SS.
getRange();
6195 Diag(Loc, diag::err_member_qualification)
6217 if (isa_and_nonnull<DecltypeType>(
6219 Diag(Loc, diag::err_decltype_in_declarator)
6234 return ActOnDecompositionDeclarator(S, D, TemplateParamLists);
6240 }
else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType))
6254 UPPC_DeclarationQualifier))
6259 if (!DC || isa<EnumDecl>(DC)) {
6265 diag::err_template_qualified_declarator_no_match)
6272 if (!IsDependentContext &&
6277 if (isa<CXXRecordDecl>(DC) && !cast<CXXRecordDecl>(DC)->
hasDefinition()) {
6279 diag::err_member_def_undefined_record)
6284 if (diagnoseQualifiedDeclaration(
6296 if (EnteringContext && IsDependentContext &&
6297 TemplateParamLists.size() != 0) {
6308 UPPC_DeclarationType))
6312 forRedeclarationInCurContext());
6316 bool IsLinkageLookup =
false;
6317 bool CreateBuiltins =
false;
6328 else if (CurContext->isFunctionOrMethod() &&
6331 IsLinkageLookup =
true;
6333 CurContext->getEnclosingNamespaceContext()->isTranslationUnit();
6334 }
else if (CurContext->getRedeclContext()->isTranslationUnit() &&
6336 CreateBuiltins =
true;
6338 if (IsLinkageLookup) {
6339 Previous.clear(LookupRedeclarationWithLinkage);
6340 Previous.setRedeclarationKind(ForExternalRedeclaration);
6343 LookupName(
Previous, S, CreateBuiltins);
6377 Previous.getFoundDecl()->isTemplateParameter()) {
6387 if (!R->
isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo))
6403 CheckExtraCXXDefaultArguments(D);
6407 bool AddToScope =
true;
6409 if (TemplateParamLists.size()) {
6414 New = ActOnTypedefDeclarator(S, D, DC, TInfo,
Previous);
6416 New = ActOnFunctionDeclarator(S, D, DC, TInfo,
Previous,
6420 New = ActOnVariableDeclarator(S, D, DC, TInfo,
Previous, TemplateParamLists,
6430 PushOnScopeChains(New, S);
6432 if (isInOpenMPDeclareTargetContext())
6433 checkDeclIsAllowedInOpenMPTarget(
nullptr, New);
6443 bool &SizeIsNegative,
6449 SizeIsNegative =
false;
6458 if (
const PointerType* PTy = dyn_cast<PointerType>(Ty)) {
6463 if (FixedType.
isNull())
return FixedType;
6465 return Qs.
apply(Context, FixedType);
6467 if (
const ParenType* PTy = dyn_cast<ParenType>(Ty)) {
6468 QualType Inner = PTy->getInnerType();
6472 if (FixedType.
isNull())
return FixedType;
6474 return Qs.
apply(Context, FixedType);
6484 SizeIsNegative, Oversized);
6497 if (Res.isSigned() && Res.isNegative()) {
6498 SizeIsNegative =
true;
6503 unsigned ActiveSizeBits =
6507 : Res.getActiveBits();
6515 return Qs.
apply(Context, FoldedArrayType);
6540 TypeLoc DstElemTL = DstATL.getElementLoc();
6559 bool &SizeIsNegative,
6563 SizeIsNegative, Oversized);
6576 unsigned FailedFoldDiagID) {
6577 bool SizeIsNegative;
6580 TInfo, Context, SizeIsNegative, Oversized);
6582 Diag(Loc, diag::ext_vla_folded_to_constant);
6589 Diag(Loc, diag::err_typecheck_negative_array_size);
6590 else if (Oversized.getBoolValue())
6591 Diag(Loc, diag::err_array_too_large) <<
toString(Oversized, 10);
6592 else if (FailedFoldDiagID)
6593 Diag(Loc, FailedFoldDiagID);
6615 return Result.empty() ? nullptr : *Result.begin();
6625 diag::err_virtual_non_function);
6629 diag::err_explicit_non_function);
6633 diag::err_noreturn_non_function);
6653 << getLangOpts().CPlusPlus17;
6661 diag::err_deduction_guide_invalid_specifier)
6670 if (!NewTD)
return nullptr;
6673 ProcessDeclAttributes(S, NewTD, D);
6675 CheckTypedefForVariablyModifiedType(S, NewTD);
6692 setFunctionHasBranchProtectedScope();
6694 if (S->getFnParent() ==
nullptr) {
6695 bool SizeIsNegative;
6709 else if (Oversized.getBoolValue())
6732 FilterLookupForScope(
Previous, DC, S,
false,
6736 Redeclaration =
true;
6737 MergeTypedefNameDecl(S, NewTD,
Previous);
6739 inferGslPointerAttribute(NewTD);
6742 if (ShadowedDecl && !Redeclaration)
6743 CheckShadow(NewTD, ShadowedDecl,
Previous);
6749 if (II->isStr(
"FILE"))
6751 else if (II->isStr(
"jmp_buf"))
6753 else if (II->isStr(
"sigjmp_buf"))
6755 else if (II->isStr(
"ucontext_t"))
6813 if (!OuterContext->
Equals(PrevOuterContext))
6822 if (!SS.
isSet())
return;
6831 unsigned kind = -1
U;
6833 if (
var->hasAttr<BlocksAttr>())
6835 else if (!
var->hasLocalStorage())
6837 }
else if (isa<ObjCIvarDecl>(
decl)) {
6839 }
else if (isa<FieldDecl>(
decl)) {
6844 Diag(
decl->getLocation(), diag::err_arc_autoreleasing_var)
6849 if (!
type->isObjCLifetimeType())
6852 lifetime =
type->getObjCARCImplicitLifetime();
6860 var->getTLSKind()) {
6861 Diag(
var->getLocation(), diag::err_arc_thread_ownership)
6871 if (
Decl->getType().hasAddressSpace())
6873 if (
Decl->getType()->isDependentType())
6884 if (getOpenCLOptions().areProgramScopeVariablesSupported(getLangOpts()) &&
6885 Var->hasGlobalStorage())
6889 if (
auto DT = dyn_cast<DecayedType>(
Type)) {
6890 auto OrigTy = DT->getOriginalType();
6891 if (!OrigTy.hasAddressSpace() && OrigTy->isArrayType()) {
6923 if (WeakRefAttr *
Attr = ND.
getAttr<WeakRefAttr>()) {
6931 if (
auto *VD = dyn_cast<VarDecl>(&ND)) {
6932 if (VD->hasInit()) {
6933 if (
const auto *
Attr = VD->getAttr<AliasAttr>()) {
6934 assert(VD->isThisDeclarationADefinition() &&
6935 !VD->isExternallyVisible() &&
"Broken AliasAttr handled late!");
6937 VD->dropAttr<AliasAttr>();
6944 if (SelectAnyAttr *
Attr = ND.
getAttr<SelectAnyAttr>()) {
6947 diag::err_attribute_selectany_non_extern_data);
6953 auto *VD = dyn_cast<VarDecl>(&ND);
6954 bool IsAnonymousNS =
false;
6957 const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(VD->getDeclContext());
6958 while (NS && !IsAnonymousNS) {
6960 NS = dyn_cast<NamespaceDecl>(NS->
getParent());
6967 bool AnonNSInMicrosoftMode = IsAnonymousNS && IsMicrosoft;
6969 (!AnonNSInMicrosoftMode &&
6978 if (
const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
6983 for (
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
6989 if (
const auto *A = ATL.
getAttrAs<LifetimeBoundAttr>()) {
6990 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
6991 if (!MD || MD->isStatic()) {
6992 S.
Diag(A->getLocation(), diag::err_lifetimebound_no_object_param)
6993 << !MD << A->getRange();
6994 }
else if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) {
6995 S.
Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor)
6996 << isa<CXXDestructorDecl>(MD) << A->getRange();
7005 bool IsSpecialization,
7006 bool IsDefinition) {
7010 bool IsTemplate =
false;
7011 if (
TemplateDecl *OldTD = dyn_cast<TemplateDecl>(OldDecl)) {
7012 OldDecl = OldTD->getTemplatedDecl();
7014 if (!IsSpecialization)
7015 IsDefinition =
false;
7017 if (
TemplateDecl *NewTD = dyn_cast<TemplateDecl>(NewDecl)) {
7018 NewDecl = NewTD->getTemplatedDecl();
7022 if (!OldDecl || !NewDecl)
7025 const DLLImportAttr *OldImportAttr = OldDecl->
getAttr<DLLImportAttr>();
7026 const DLLExportAttr *OldExportAttr = OldDecl->
getAttr<DLLExportAttr>();
7027 const DLLImportAttr *NewImportAttr = NewDecl->
getAttr<DLLImportAttr>();
7028 const DLLExportAttr *NewExportAttr = NewDecl->
getAttr<DLLExportAttr>();
7032 bool HasNewAttr = (NewImportAttr && !NewImportAttr->isInherited()) ||
7033 (NewExportAttr && !NewExportAttr->isInherited());
7039 bool AddsAttr = !(OldImportAttr || OldExportAttr) && HasNewAttr;
7041 if (AddsAttr && !IsSpecialization && !OldDecl->
isImplicit()) {
7043 bool JustWarn =
false;
7045 auto *VD = dyn_cast<VarDecl>(OldDecl);
7046 if (VD && !VD->getDescribedVarTemplate())
7048 auto *FD = dyn_cast<FunctionDecl>(OldDecl);
7057 if (!isa<FunctionDecl>(OldDecl) || !NewImportAttr)
7060 unsigned DiagID = JustWarn ? diag::warn_attribute_dll_redeclaration
7061 : diag::err_attribute_dll_redeclaration;
7064 << (NewImportAttr ? (
const Attr *)NewImportAttr : NewExportAttr);
7077 bool IsInline =
false, IsStaticDataMember =
false, IsQualifiedFriend =
false;
7079 if (
const auto *VD = dyn_cast<VarDecl>(NewDecl)) {
7082 IsStaticDataMember = VD->isStaticDataMember();
7083 IsDefinition = VD->isThisDeclarationADefinition(S.
Context) !=
7085 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(NewDecl)) {
7086 IsInline = FD->isInlined();
7087 IsQualifiedFriend = FD->getQualifier() &&
7091 if (OldImportAttr && !HasNewAttr &&
7092 (!IsInline || (IsMicrosoftABI && IsTemplate)) && !IsStaticDataMember &&
7094 if (IsMicrosoftABI && IsDefinition) {
7095 if (IsSpecialization) {
7098 diag::err_attribute_dllimport_function_specialization_definition);
7099 S.
Diag(OldImportAttr->getLocation(), diag::note_attribute);
7100 NewDecl->
dropAttr<DLLImportAttr>();
7103 diag::warn_redeclaration_without_import_attribute)
7106 NewDecl->
dropAttr<DLLImportAttr>();
7107 NewDecl->
addAttr(DLLExportAttr::CreateImplicit(
7108 S.
Context, NewImportAttr->getRange()));
7110 }
else if (IsMicrosoftABI && IsSpecialization) {
7111 assert(!IsDefinition);
7115 diag::warn_redeclaration_without_attribute_prev_attribute_ignored)
7116 << NewDecl << OldImportAttr;
7118 S.
Diag(OldImportAttr->getLocation(), diag::note_previous_attribute);
7119 OldDecl->
dropAttr<DLLImportAttr>();
7120 NewDecl->
dropAttr<DLLImportAttr>();
7122 }
else if (IsInline && OldImportAttr && !IsMicrosoftABI) {
7125 OldDecl->
dropAttr<DLLImportAttr>();
7126 NewDecl->
dropAttr<DLLImportAttr>();
7128 diag::warn_dllimport_dropped_from_inline_function)
7129 << NewDecl << OldImportAttr;
7136 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewDecl)) {
7138 !NewImportAttr && !NewExportAttr) {
7139 if (
const DLLExportAttr *ParentExportAttr =
7140 MD->getParent()->getAttr<DLLExportAttr>()) {
7141 DLLExportAttr *NewAttr = ParentExportAttr->clone(S.
Context);
7142 NewAttr->setInherited(
true);
7182 template<
typename T>
7186 if (!D->isInExternCContext() || D->template hasAttr<OverloadableAttr>())
7190 if (S.
getLangOpts().CUDA && (D->template hasAttr<CUDADeviceAttr>() ||
7191 D->template hasAttr<CUDAHostAttr>()))
7194 return D->isExternC();
7200 isa<OMPDeclareMapperDecl>(DC))
7209 if (isa<RequiresExprBodyDecl>(DC))
7211 llvm_unreachable(
"Unexpected context");
7217 isa<OMPDeclareReductionDecl>(DC) || isa<OMPDeclareMapperDecl>(DC))
7221 llvm_unreachable(
"Unexpected context");
7268 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
7269 return FD->isExternC();
7270 if (
const auto *VD = dyn_cast<VarDecl>(D))
7271 return VD->isExternC();
7273 llvm_unreachable(
"Unknown type of decl!");
7286 diag::err_opencl_type_can_only_be_used_as_function_parameter)
7300 diag::err_invalid_type_for_program_scope_var)
7329 Se.
Diag(NewVD->
getLocation(), diag::err_opencl_half_declaration) << R;
7362 Se.
Diag(NewVD->
getLocation(), diag::err_opencl_nonconst_global_sampler);
7372 template <
typename AttrTy>
7375 if (
const auto *Attribute = TND->
getAttr<AttrTy>()) {
7376 AttrTy *Clone = Attribute->clone(S.
Context);
7377 Clone->setInherited(
true);
7405 if (
const auto *ConstDecl = RD->
getAttr<ReadOnlyPlacementAttr>()) {
7407 S.
Diag(ConstDecl->getLocation(), diag::note_enforce_read_only_placement);
7425 if (!Decomp.bindings().empty()) {
7426 II = Decomp.bindings()[0].Name;
7446 bool IsLocalExternDecl = SC ==
SC_Extern &&
7447 adjustContextForLocalExternDecl(DC);
7458 !D.
getAsmLabel() && !getSourceManager().isInSystemMacro(
7464 getLangOpts().
CPlusPlus17 ? diag::ext_register_storage_class
7465 : diag::warn_deprecated_register)
7471 if (!DC->
isRecord() && S->getFnParent() ==
nullptr) {
7487 bool IsMemberSpecialization =
false;
7488 bool IsVariableTemplateSpecialization =
false;
7490 bool IsVariableTemplate =
false;
7499 ParsingInitForAutoVars.insert(NewVD);
7507 NTCUC_AutoVar, NTCUK_Destruct);
7509 bool Invalid =
false;
7511 if (DC->
isRecord() && !CurContext->isRecord()) {
7518 diag::err_static_out_of_line)
7530 diag::err_storage_class_for_static_member)
7534 llvm_unreachable(
"C storage class in c++!");
7538 if (SC ==
SC_Static && CurContext->isRecord()) {
7539 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) {
7545 if (Ctxt->isFunctionOrMethod()) {
7546 FunctionOrMethod = Ctxt;
7549 const CXXRecordDecl *ParentDecl = dyn_cast<CXXRecordDecl>(Ctxt);
7551 AnonStruct = ParentDecl;
7555 if (FunctionOrMethod) {
7559 diag::err_static_data_member_not_allowed_in_local_class)
7560 << Name << RD->getDeclName() << RD->getTagKind();
7561 }
else if (AnonStruct) {
7566 diag::err_static_data_member_not_allowed_in_anon_struct)
7569 }
else if (RD->isUnion()) {
7574 ? diag::warn_cxx98_compat_static_data_member_in_union
7575 : diag::ext_static_data_member_in_union) << Name;
7582 bool InvalidScope =
false;
7583 TemplateParams = MatchTemplateParametersToScopeSpecifier(
7590 false, IsMemberSpecialization, InvalidScope);
7591 Invalid |= InvalidScope;
7593 if (TemplateParams) {
7594 if (!TemplateParams->
size() &&
7599 diag::err_template_variable_noparams)
7603 TemplateParams =
nullptr;
7606 if (CheckTemplateDeclScope(S, TemplateParams))
7611 IsVariableTemplateSpecialization =
true;
7615 IsVariableTemplate =
true;
7620 ? diag::warn_cxx11_compat_variable_template
7621 : diag::ext_variable_template);
7626 if (!TemplateParamLists.empty() && IsMemberSpecialization &&
7627 CheckTemplateDeclScope(S, TemplateParamLists.back()))
7631 "should have a 'template<>' for this decl");
7634 if (IsVariableTemplateSpecialization) {
7636 TemplateParamLists.size() > 0
7637 ? TemplateParamLists[0]->getTemplateLoc()
7639 DeclResult Res = ActOnVarTemplateSpecialization(
7640 S, D, TInfo, TemplateKWLoc, TemplateParams, SC,
7644 NewVD = cast<VarDecl>(Res.
get());
7655 if (IsVariableTemplate) {
7658 TemplateParams, NewVD);
7665 ParsingInitForAutoVars.insert(NewVD);
7677 unsigned VDTemplateParamLists = TemplateParams ? 1 : 0;
7678 if (TemplateParamLists.size() > VDTemplateParamLists)
7680 Context, TemplateParamLists.drop_back(VDTemplateParamLists));
7687 }
else if (CurContext->isFunctionOrMethod()) {
7690 diag::err_inline_declaration_block_scope) << Name
7694 getLangOpts().
CPlusPlus17 ? diag::warn_cxx14_compat_inline_variable
7695 : diag::ext_inline_variable);
7706 if (IsLocalExternDecl) {
7709 B->setLocalExternDecl();
7714 bool EmitTLSUnsupportedError =
false;
7727 diag::err_thread_non_global)
7730 if (getLangOpts().
CUDA || getLangOpts().OpenMPIsDevice ||
7731 getLangOpts().SYCLIsDevice) {
7735 EmitTLSUnsupportedError =
true;
7742 diag::err_thread_unsupported);
7753 diag::err_constexpr_wrong_decl_kind)
7763 (getLangOpts().CPlusPlus17 ||
7771 diag::err_constinit_local_variable);
7773 NewVD->
addAttr(ConstInitAttr::Create(
7788 if (SC ==
SC_Static && S->getFnParent() !=
nullptr &&
7793 diag::warn_static_local_in_extern_inline);
7794 MaybeSuggestAddingStaticToDecl(CurFD);
7799 if (IsVariableTemplateSpecialization)
7804 else if (IsMemberSpecialization)
7819 B->setModulePrivate();
7823 if (getLangOpts().
OpenCL) {
7824 deduceOpenCLAddressSpace(NewVD);
7829 diag::err_opencl_unknown_type_specifier)
7830 << getLangOpts().getOpenCLVersionString()
7837 ProcessDeclAttributes(S, NewVD, D);
7845 copyAttrFromTypedefToDecl<AllocSizeAttr>(*
this, NewVD, TT);
7847 if (getLangOpts().
CUDA || getLangOpts().OpenMPIsDevice ||
7848 getLangOpts().SYCLIsDevice) {
7849 if (EmitTLSUnsupportedError &&
7851 (getLangOpts().OpenMPIsDevice &&
7852 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(NewVD))))
7854 diag::err_thread_unsupported);
7856 if (EmitTLSUnsupportedError &&
7857 (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice)))
7861 if (SC ==
SC_None && S->getFnParent() !=
nullptr &&
7862 (NewVD->
hasAttr<CUDASharedAttr>() ||
7863 NewVD->
hasAttr<CUDAConstantAttr>())) {
7871 assert(!NewVD->
hasAttr<DLLImportAttr>() ||
7872 NewVD->
getAttr<DLLImportAttr>()->isInherited() ||
7877 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewVD))
7885 if (S->getFnParent() !=
nullptr) {
7889 Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) <<
Label;
7895 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) <<
Label;
7906 bool HasSizeMismatch;
7908 if (!TI.isValidGCCRegisterName(
Label))
7909 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) <<
Label;
7910 else if (!TI.validateGlobalRegisterVariable(
Label,
7913 Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) <<
Label;
7914 else if (HasSizeMismatch)
7915 Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) <<
Label;
7927 }
else if (!ExtnameUndeclaredIdentifiers.empty()) {
7928 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
7930 if (I != ExtnameUndeclaredIdentifiers.end()) {
7933 ExtnameUndeclaredIdentifiers.erase(I);
7942 ? getShadowedDeclaration(NewVD,
Previous)
7950 IsMemberSpecialization ||
7951 IsVariableTemplateSpecialization);
7959 isDeclInScope(
Previous.getFoundDecl(), OriginalDC, S,
false));
7966 CheckMemberSpecialization(NewVD,
Previous))
7972 isa<FieldDecl>(
Previous.getFoundDecl()) &&
7989 if (!IsVariableTemplateSpecialization)
8001 if (CheckTemplateParameterList(
8007 ? TPC_ClassTemplateMember
8013 if (PrevVarTemplate &&
8021 CheckShadow(NewVD, ShadowedDecl,
Previous);
8023 ProcessPragmaWeak(S, NewVD);
8029 RegisterLocallyScopedExternCDecl(NewVD, S);
8033 Decl *ManglingContextDecl;
8034 std::tie(MCtx, ManglingContextDecl) =
8045 if (Name.getAsIdentifierInfo() && Name.getAsIdentifierInfo()->isStr(
"main") &&
8069 ActOnDocumentableDecl(NewTemplate);
8074 CompleteMemberSpecialization(NewVD,
Previous);
8095 if (isa<TypeAliasDecl>(ShadowedDecl))
8097 else if (isa<TypedefDecl>(ShadowedDecl))
8099 else if (isa<BindingDecl>(ShadowedDecl))
8101 else if (isa<RecordDecl>(OldDC))
8140 return isa<VarDecl, FieldDecl, BindingDecl>(ShadowedDecl) ? ShadowedDecl
8156 return isa<TypedefNameDecl>(ShadowedDecl) ? ShadowedDecl :
nullptr;
8167 return isa<VarDecl, FieldDecl, BindingDecl>(ShadowedDecl) ? ShadowedDecl
8184 if (
FieldDecl *FD = dyn_cast<FieldDecl>(ShadowedDecl)) {
8192 if (isa<CXXConstructorDecl>(NewDC))
8193 if (
const auto PVD = dyn_cast<ParmVarDecl>(D)) {
8196 ShadowingDecls.insert({PVD->getCanonicalDecl(), FD});
8201 if (
VarDecl *shadowedVar = dyn_cast<VarDecl>(ShadowedDecl))
8202 if (shadowedVar->isExternC()) {
8205 for (
auto *I : shadowedVar->redecls())
8206 if (I->isFileVarDecl()) {
8214 unsigned WarningDiag = diag::warn_decl_shadow;
8216 if (isa<VarDecl>(D) && isa<VarDecl>(ShadowedDecl) && NewDC &&
8217 isa<CXXMethodDecl>(NewDC)) {
8218 if (
const auto *RD = dyn_cast<CXXRecordDecl>(NewDC->
getParent())) {
8220 if (RD->getLambdaCaptureDefault() ==
LCD_None) {
8222 const auto *LSI = cast<LambdaScopeInfo>(getCurFunction());
8226 WarningDiag = diag::warn_decl_shadow_uncaptured_local;
8230 cast<LambdaScopeInfo>(getCurFunction())
8231 ->ShadowingDecls.push_back(
8232 {cast<VarDecl>(D), cast<VarDecl>(ShadowedDecl)});
8237 if (cast<VarDecl>(ShadowedDecl)->hasLocalStorage()) {
8241 ParentDC && !ParentDC->
Equals(OldDC);
8245 if (!isa<BlockDecl>(ParentDC) && !isa<CapturedDecl>(ParentDC) &&
8275 Diag(CaptureLoc, diag::note_var_explicitly_captured_here)
8284 const VarDecl *ShadowedDecl = Shadow.ShadowedDecl;
8289 ? diag::warn_decl_shadow_uncaptured_local
8290 : diag::warn_decl_shadow)
8291 << Shadow.VD->getDeclName()
8294 Diag(CaptureLoc, diag::note_var_explicitly_captured_here)
8295 << Shadow.VD->getDeclName() << 0;
8302 if (Diags.isIgnored(diag::warn_decl_shadow, D->
getLocation()))
8308 if (
NamedDecl *ShadowedDecl = getShadowedDeclaration(D, R))
8309 CheckShadow(D, ShadowedDecl, R);
8316 if (!getLangOpts().
CPlusPlus || ShadowingDecls.empty())
8319 auto *DRE = dyn_cast<DeclRefExpr>(E);
8322 const NamedDecl *D = cast<NamedDecl>(DRE->getDecl()->getCanonicalDecl());
8323 auto I = ShadowingDecls.find(D);
8324 if (I == ShadowingDecls.end())
8326 const NamedDecl *ShadowedDecl = I->second;
8328 Diag(Loc, diag::warn_modifying_shadowing_decl) << D << OldDC;
8333 ShadowingDecls.erase(I);
8338 template<
typename T>
8341 assert(S.
getLangOpts().CPlusPlus &&
"only C++ has extern \"C\"");
8362 if (!isa<VarDecl>(ND))
8372 if (isa<VarDecl>(*I)) {
8382 if (isa<VarDecl>(*I)) {
8400 assert(Prev &&
"should have found a previous declaration to diagnose");
8402 Prev = FD->getFirstDecl();
8404 Prev = cast<VarDecl>(Prev)->getFirstDecl();
8406 S.
Diag(ND->getLocation(), diag::err_extern_c_global_conflict)
8421 template<
typename T>
8428 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
8440 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit())
8465 CheckAlignasUnderalignment(NewVD);
8487 if (getLangOpts().OpenCLVersion == 120 &&
8488 !getOpenCLOptions().isAvailableOption(
"cl_clang_storage_class_specifiers",
8496 if (getLangOpts().
OpenCL) {
8501 if (NewVD->
hasAttr<BlocksAttr>()) {
8510 Diag(NewVD->
getLocation(), diag::err_opencl_invalid_block_declaration)
8516 Diag(NewVD->
getLocation(), diag::err_opencl_extern_block_declaration);
8528 getOpenCLOptions().areProgramScopeVariablesSupported(
8531 if (getOpenCLOptions().areProgramScopeVariablesSupported(getLangOpts()))
8532 Diag(NewVD->
getLocation(), diag::err_opencl_global_invalid_addr_space)
8533 <<
Scope <<
"global or constant";
8535 Diag(NewVD->
getLocation(), diag::err_opencl_global_invalid_addr_space)
8536 <<
Scope <<
"constant";
8552 if (FD && !FD->
hasAttr<OpenCLKernelAttr>()) {
8564 if (FD && FD->
hasAttr<OpenCLKernelAttr>()) {
8565 if (!getCurScope()->isFunctionScope()) {
8589 && !NewVD->
hasAttr<BlocksAttr>()) {
8593 assert(!getLangOpts().ObjCAutoRefCount);
8599 if (isVM || NewVD->
hasAttr<CleanupAttr>() ||
8601 setFunctionHasBranchProtectedScope();
8605 bool SizeIsNegative;
8611 FixedT = FixedTInfo->
getType();
8612 else if (FixedTInfo) {
8674 if (isVM && NewVD->
hasAttr<BlocksAttr>()) {
8682 diag::err_constexpr_var_non_literal)) {
8697 const FunctionDecl *FD = cast<FunctionDecl>(CurContext);
8698 llvm::StringMap<bool> CallerFeatureMap;
8701 "sve", CallerFeatureMap)) {
8702 Diag(NewVD->
getLocation(), diag::err_sve_vector_in_non_sve_target) << T;
8722 CheckVariableDeclarationType(NewVD);
8762 dyn_cast<CXXMethodDecl>(BaseND->getCanonicalDecl());
8764 IsOverload(MD, BaseMD,
false,
8771 if (Overridden.insert(BaseMD).second) {
8773 CheckOverridingFunctionReturnType(MD, BaseMD);
8774 CheckOverridingFunctionAttributes(MD, BaseMD);
8775 CheckOverridingFunctionExceptionSpec(MD, BaseMD);
8776 CheckIfOverriddenFunctionIsMarkedFinal(MD, BaseMD);
8788 return !Overridden.empty();
8794 struct ActOnFDArgs {
8810 : Context(Context), OriginalFD(TypoFD),
8813 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
8819 CDeclEnd = candidate.
end();
8820 CDecl != CDeclEnd; ++CDecl) {
8827 if (
Parent &&
Parent->getCanonicalDecl() == ExpectedParent)
8829 }
else if (!ExpectedParent) {
8838 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
8839 return std::make_unique<DifferentNameValidatorCCC>(*
this);
8851 TypoCorrectedFunctionDefinitions.insert(F);
8865 ActOnFDArgs &ExtraArgs,
bool IsLocalFriend,
Scope *S) {
8871 bool IsDefinition = ExtraArgs.D.isFunctionDefinition();
8873 IsLocalFriend ? diag::err_no_matching_local_friend :
8875 diag::err_member_decl_does_not_match;
8887 "Cannot have an ambiguity in previous-declaration lookup");
8889 DifferentNameValidatorCCC CCC(SemaRef.
Context, NewFD,
8891 if (!Prev.
empty()) {
8893 Func != FuncEnd; ++Func) {
8900 MismatchedParams.empty() ? 0 : MismatchedParams.front() + 1;
8901 NearMatches.push_back(std::make_pair(FD, ParamNum));
8908 IsLocalFriend ?
nullptr : NewDC))) {
8911 ExtraArgs.D.getIdentifierLoc());
8915 CDeclEnd = Correction.
end();
8916 CDecl != CDeclEnd; ++CDecl) {
8923 bool wasRedeclaration = ExtraArgs.D.isRedeclaration();
8936 ExtraArgs.S, ExtraArgs.D,
8939 ExtraArgs.AddToScope);
8950 if ((*I)->getCanonicalDecl() == Canonical)
8957 SemaRef.
PDiag(IsLocalFriend
8958 ? diag::err_no_matching_local_friend_suggest
8959 : diag::err_member_decl_does_not_match_suggest)
8960 << Name << NewDC << IsDefinition);
8965 ExtraArgs.D.SetIdentifier(Name.getAsIdentifierInfo(),
8966 ExtraArgs.D.getIdentifierLoc());
8967 ExtraArgs.D.setRedeclaration(wasRedeclaration);
8973 << Name << NewDC << IsDefinition << NewFD->
getLocation();
8975 bool NewFDisConst =
false;
8977 NewFDisConst = NewMD->isConst();
8980 NearMatch = NearMatches.begin(), NearMatchEnd = NearMatches.end();
8981 NearMatch != NearMatchEnd; ++NearMatch) {
8984 bool FDisConst = MD && MD->
isConst();
8985 bool IsMember = MD || !IsLocalFriend;
8988 if (
unsigned Idx = NearMatch->second) {
8992 SemaRef.
Diag(Loc, IsMember ? diag::note_member_def_close_param_match
8993 : diag::note_local_decl_close_param_match)
8996 }
else if (FDisConst != NewFDisConst) {
8997 SemaRef.
Diag(FD->
getLocation(), diag::note_member_def_close_const_match)
9001 .getConstQualifierLoc())
9004 .getLocWithOffset(1),
9008 IsMember ? diag::note_member_def_close_match
9009 : diag::note_local_decl_close_match);
9016 default: llvm_unreachable(
"Unknown storage class!");
9021 diag::err_typecheck_sclass_func);
9038 diag::err_static_block_func);
9054 bool &IsVirtualOkay) {
9079 "Strict prototypes are required");
9097 diag::err_constexpr_wrong_decl_kind)
9098 <<
static_cast<int>(ConstexprKind);
9116 "Constructors can only be declared in a member context");
9122 isInline,
false, ConstexprKind,
9133 false, ConstexprKind,
9134 TrailingRequiresClause);
9146 IsVirtualOkay =
true;
9158 true, ConstexprKind, TrailingRequiresClause);
9164 diag::err_conv_function_not_member);
9172 IsVirtualOkay =
true;
9177 TrailingRequiresClause);
9180 if (TrailingRequiresClause)
9182 diag::err_trailing_requires_clause_on_deduction_guide)
9194 if (Name.getAsIdentifierInfo() &&
9195 Name.getAsIdentifierInfo() == cast<CXXRecordDecl>(DC)->getIdentifier()){
9207 IsVirtualOkay = !
Ret->isStatic();
9221 true , ConstexprKind, TrailingRequiresClause);
9238 StringRef SizeTypeNames[] = {
"size_t",
"intptr_t",
"uintptr_t",
"ptrdiff_t"};
9246 if (Names.end() != Match)
9251 }
while (DesugaredTy != Ty);
9284 "__cl_clang_non_portable_kernel_param_types", S.
getLangOpts())) {
9286 bool IsStandardLayoutType =
true;
9292 if (!CXXRec->hasDefinition())
9294 if (!CXXRec || !CXXRec->hasDefinition() || !CXXRec->isStandardLayout())
9295 IsStandardLayoutType =
false;
9298 !IsStandardLayoutType)
9341 "__cl_clang_non_portable_kernel_param_types", S.
getLangOpts()) &&
9355 llvm::SmallPtrSetImpl<const Type *> &ValidTypes) {
9407 S.
Diag(Loc, diag::note_entity_declared_at) << PT;
9430 HistoryStack.push_back(
nullptr);
9439 VisitStack.push_back(RecTy->
getDecl());
9440 assert(VisitStack.back() &&
"First decl null?");
9443 const Decl *Next = VisitStack.pop_back_val();
9445 assert(!HistoryStack.empty());
9447 if (
const FieldDecl *Hist = HistoryStack.pop_back_val())
9448 ValidTypes.insert(Hist->getType().getTypePtr());
9456 if (
const FieldDecl *Field = dyn_cast<FieldDecl>(Next)) {
9457 HistoryStack.push_back(Field);
9459 QualType FieldTy = Field->getType();
9463 "Unexpected type.");
9468 RD = cast<RecordDecl>(Next);
9472 VisitStack.push_back(
nullptr);
9474 for (
const auto *FD : RD->
fields()) {
9485 VisitStack.push_back(FD);
9496 diag::err_record_with_pointers_kernel_param)
9503 S.
Diag(OrigRecDecl->getLocation(), diag::note_within_field_of_type)
9504 << OrigRecDecl->getDeclName();
9509 I = HistoryStack.begin() + 1,
9510 E = HistoryStack.end();
9523 }
while (!VisitStack.empty());
9539 while (S->isClassScope() ||
9540 (LangOpts.CPlusPlus &&
9541 S->isFunctionPrototypeScope()) ||
9543 (S->getEntity() && S->getEntity()->isTransparentContext()))
9550 unsigned BuiltinID) {
9551 switch (BuiltinID) {
9552 case Builtin::BI__GetExceptionInfo:
9556 case Builtin::BIaddressof:
9557 case Builtin::BI__addressof:
9558 case Builtin::BIforward:
9559 case Builtin::BIforward_like:
9560 case Builtin::BImove:
9561 case Builtin::BImove_if_noexcept:
9562 case Builtin::BIas_const: {
9587 llvm::append_range(TemplateParamLists, TemplateParamListsRef);
9589 if (!TemplateParamLists.empty() &&
9590 Invented->getDepth() == TemplateParamLists.back()->getDepth())
9591 TemplateParamLists.back() = Invented;
9593 TemplateParamLists.push_back(Invented);
9603 diag::err_invalid_thread)
9610 bool isFriend =
false;
9612 bool isMemberSpecialization =
false;
9613 bool isFunctionTemplateSpecialization =
false;
9615 bool isDependentClassScopeExplicitSpecialization =
false;
9616 bool HasExplicitTemplateArgs =
false;
9619 bool isVirtualOkay =
false;
9622 bool IsLocalExternDecl = adjustContextForLocalExternDecl(DC);
9626 if (!NewFD)
return nullptr;
9628 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer())
9636 if (IsLocalExternDecl)
9645 bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlusModules ||
9668 if (
Parent->isInterface() && cast<CXXMethodDecl>(NewFD)->isUserProvided())
9673 if (isVirtual &&
Parent->isUnion()) {
9678 Parent->hasAttr<SYCLSpecialClassAttr>() &&
9681 if (
auto *Def =
Parent->getDefinition())
9682 Def->setInitMethod(
true);
9687 isMemberSpecialization =
false;
9688 isFunctionTemplateSpecialization =
false;
9694 bool Invalid =
false;
9696 MatchTemplateParametersToScopeSpecifier(
9702 TemplateParamLists, isFriend, isMemberSpecialization,
9704 if (TemplateParams) {
9706 if (CheckTemplateDeclScope(S, TemplateParams))
9709 if (TemplateParams->
size() > 0) {
9723 if (RebuildTemplateParamsInCurrentInstantiation(TemplateParams))
9729 Name, TemplateParams,
9735 if (TemplateParamLists.size() > 1) {
9742 isFunctionTemplateSpecialization =
true;
9744 if (TemplateParamLists.size() > 0)
9760 InsertLoc = getLocForEndOfToken(InsertLoc);
9764 << Name << RemoveRange
9772 if (!TemplateParamLists.empty() && isMemberSpecialization &&
9773 CheckTemplateDeclScope(S, TemplateParamLists.back()))
9778 if (TemplateParamLists.size() > 0)
9785 if (FunctionTemplate)
9795 if (!isVirtualOkay) {
9797 diag::err_virtual_non_function);
9798 }
else if (!CurContext->isRecord()) {
9801 diag::err_virtual_out_of_class)
9807 diag::err_virtual_member_function_template)
9821 (isFriend && CurContext->isDependentContext())) &&
9840 if (CurContext->isFunctionOrMethod()) {
9843 diag::err_inline_declaration_block_scope) << Name
9853 !isa<CXXDeductionGuideDecl>(NewFD)) {
9854 if (!CurContext->isRecord()) {
9857 diag::err_explicit_out_of_class)
9859 }
else if (!isa<CXXConstructorDecl>(NewFD) &&
9860 !isa<CXXConversionDecl>(NewFD)) {
9864 diag::err_explicit_non_ctor_or_conv_function)
9878 if (isa<CXXDestructorDecl>(NewFD) &&
9882 <<
static_cast<int>(ConstexprKind);
9896 diag::err_invalid_consteval_decl_kind)
9904 if (isFunctionTemplateSpecialization) {
9907 Diag(ModulePrivateLoc, diag::err_module_private_specialization)
9912 if (FunctionTemplate)
9918 if (FunctionTemplate) {
9942 if (isa<CXXMethodDecl>(NewFD) && DC == CurContext &&
9953 if (SC ==
SC_Static && isa<CXXMethodDecl>(NewFD) &&
9954 !CurContext->isRecord()) {
9968 cast<CXXRecordDecl>(DC)->getDescribedClassTemplate()) ||
9970 ? diag::ext_static_out_of_line : diag::err_static_out_of_line)
9978 if ((Name.getCXXOverloadedOperator() == OO_Delete ||
9979 Name.getCXXOverloadedOperator() == OO_Array_Delete) &&
9995 PendingInlineFuncDecls.insert(NewFD);
10002 isMemberSpecialization ||
10003 isFunctionTemplateSpecialization);
10012 }
else if (!ExtnameUndeclaredIdentifiers.empty()) {
10013 llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
10015 if (I != ExtnameUndeclaredIdentifiers.end()) {
10018 ExtnameUndeclaredIdentifiers.erase(I);
10038 for (
unsigned i = 0, e = FTI.
NumParams; i != e; ++i) {
10042 Params.push_back(Param);
10057 auto *TD = dyn_cast<TagDecl>(NonParmDecl);
10062 if (
auto *ECD = dyn_cast<EnumConstantDecl>(NonParmDecl))
10063 TD = cast<EnumDecl>(ECD->getDeclContext());
10067 DeclContext *TagDC = TD->getLexicalDeclContext();
10071 TD->setDeclContext(NewFD);
10079 if (TagDC != PrototypeTagContext)
10080 TD->setLexicalDeclContext(TagDC);
10094 for (
const auto &AI : FT->param_types()) {
10098 Params.push_back(Param);
10102 "Should not need args for typedef of non-prototype fn");
10106 NewFD->setParams(Params);
10109 NewFD->
addAttr(C11NoReturnAttr::Create(Context,
10123 !NewFD->
hasAttr<SectionAttr>())
10124 NewFD->
addAttr(PragmaClangTextSectionAttr::CreateImplicit(
10125 Context, PragmaClangTextSection.SectionName,
10130 !NewFD->
hasAttr<SectionAttr>()) {
10131 NewFD->
addAttr(SectionAttr::CreateImplicit(
10132 Context, CodeSegStack.CurrentValue->getString(),
10134 SectionAttr::Declspec_allocate));
10135 if (UnifySection(CodeSegStack.CurrentValue->getString(),
10145 !NewFD->
hasAttr<StrictGuardStackCheckAttr>())
10146 NewFD->
addAttr(StrictGuardStackCheckAttr::CreateImplicit(
10147 Context, PragmaClangTextSection.PragmaLocation,
10152 if (!NewFD->
hasAttr<CodeSegAttr>()) {
10153 if (
Attr *SAttr = getImplicitCodeSegOrSectionAttrForFunction(NewFD,
10160 ProcessDeclAttributes(S, NewFD, D);
10161 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
10162 if (NewTVA && !NewTVA->isDefaultVersion() &&
10165 AddToScope =
false;
10169 if (getLangOpts().OpenCL) {
10174 Diag(NewFD->
getLocation(), diag::err_return_value_with_address_space);
10179 if (getLangOpts().
HLSL) {
10180 auto &
TargetInfo = getASTContext().getTargetInfo();
10185 S->getDepth() == 0) {
10186 CheckHLSLEntryPoint(NewFD);
10190 HLSLShaderAttr::ShaderType ShaderType =
10191 static_cast<HLSLShaderAttr::ShaderType
>(
10195 if (HLSLShaderAttr *
Attr = mergeHLSLShaderAttr(NewFD, AL, ShaderType))
10203 Diag(NewFD->
getLocation(), diag::err_return_value_with_address_space);
10214 CheckMSVCRTEntryPoint(NewFD);
10218 isMemberSpecialization,
10225 "previous declaration set still overloaded");
10237 CC ==
CC_X86StdCall ? diag::warn_cconv_knr : diag::err_cconv_knr;
10247 NTCUC_FunctionReturn, NTCUK_Destruct|NTCUK_Copy);
10260 diag::ext_operator_new_delete_declared_inline)
10271 translateTemplateArguments(TemplateArgsPtr,
10274 HasExplicitTemplateArgs =
true;
10277 HasExplicitTemplateArgs =
false;
10278 }
else if (FunctionTemplate) {
10283 HasExplicitTemplateArgs =
false;
10285 assert((isFunctionTemplateSpecialization ||
10287 "should have a 'template<>' for this decl");
10289 isFunctionTemplateSpecialization =
true;
10291 }
else if (isFriend && isFunctionTemplateSpecialization) {
10298 HasExplicitTemplateArgs =
true;
10309 if (getLangOpts().
CUDA && !isFunctionTemplateSpecialization)
10310 maybeAddCUDAHostDeviceAttrs(NewFD,
Previous);
10316 if (isFunctionTemplateSpecialization && isFriend &&
10320 assert(HasExplicitTemplateArgs &&
10321 "friend function specialization without template args");
10322 if (CheckDependentFunctionTemplateSpecialization(NewFD, TemplateArgs,
10325 }
else if (isFunctionTemplateSpecialization) {
10326 if (CurContext->isDependentContext() && CurContext->isRecord()
10328 isDependentClassScopeExplicitSpecialization =
true;
10330 CheckFunctionTemplateSpecialization(
10331 NewFD, (HasExplicitTemplateArgs ? &TemplateArgs :
nullptr),
10343 diag::err_explicit_specialization_inconsistent_storage_class)
10350 diag::ext_explicit_specialization_storage_class)
10354 }
else if (isMemberSpecialization && isa<CXXMethodDecl>(NewFD)) {
10355 if (CheckMemberSpecialization(NewFD,
Previous))
10360 if (!isDependentClassScopeExplicitSpecialization) {
10365 CheckMSVCRTEntryPoint(NewFD);
10369 isMemberSpecialization,
10379 "previous declaration set still overloaded");
10381 NamedDecl *PrincipalDecl = (FunctionTemplate
10382 ? cast<NamedDecl>(FunctionTemplate)
10391 if (FunctionTemplate) FunctionTemplate->
setAccess(Access);
10400 if (FunctionTemplate) {
10408 ? TPC_FriendFunctionTemplateDefinition
10409 : TPC_FriendFunctionTemplate)
10413 ? TPC_ClassTemplateMember
10414 : TPC_FunctionTemplate);
10420 struct ActOnFDArgs ExtraArgs = { S, D, TemplateParamLists,
10443 (!
Previous.empty() && CurContext->isDependentContext()))) {
10466 *
this,
Previous, NewFD, ExtraArgs,
false,
nullptr)) {
10467 AddToScope = ExtraArgs.AddToScope;
10474 }
else if (isFriend && cast<CXXRecordDecl>(CurContext)->isLocalClass()) {
10476 *
this,
Previous, NewFD, ExtraArgs,
true, S)) {
10477 AddToScope = ExtraArgs.AddToScope;
10482 isa<CXXMethodDecl>(NewFD) && NewFD->
isOutOfLine() &&
10483 !isFriend && !isFunctionTemplateSpecialization &&
10484 !isMemberSpecialization) {
10501 if (
unsigned BuiltinID = II->getBuiltinID()) {
10503 if (!InStdNamespace &&
10509 NewFD->
addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
10512 LookupNecessaryTypesForBuiltin(S, BuiltinID);
10518 NewFD->
addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
10523 NewFD->
addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID));
10529 ProcessPragmaWeak(S, NewFD);
10532 AddKnownFunctionAttributes(NewFD);
10534 if (NewFD->
hasAttr<OverloadableAttr>() &&
10537 diag::err_attribute_overloadable_no_prototype)
10539 NewFD->
dropAttr<OverloadableAttr>();
10545 AddPushedVisibilityAttribute(NewFD);
10549 AddCFAuditedAttribute(NewFD);
10554 AddRangeBasedOptnone(NewFD);
10555 AddImplicitMSFunctionNoBuiltinAttr(NewFD);
10556 AddSectionMSAllocText(NewFD);
10557 ModifyFnAttributesMSPragmaOptimize(NewFD);
10564 RegisterLocallyScopedExternCDecl(NewFD, S);
10572 isMemberSpecialization ||
10573 isFunctionTemplateSpecialization,
10577 if (getLangOpts().
CUDA) {
10579 if (II && II->
isStr(getCudaConfigureFuncName()) &&
10584 << getCudaConfigureFuncName();
10591 if (!getLangOpts().CUDAAllowVariadicFunctions && NewFD->
isVariadic() &&
10592 (NewFD->
hasAttr<CUDADeviceAttr>() ||
10593 NewFD->
hasAttr<CUDAGlobalAttr>()) &&
10600 MarkUnusedFileScopedDecl(NewFD);
10604 if (getLangOpts().
OpenCL && NewFD->
hasAttr<OpenCLKernelAttr>()) {
10624 if (getLangOpts().OpenCLCPlusPlus) {
10629 if (FunctionTemplate) {
10639 if (isFriend && FunctionTemplate &&
10640 FriendConstraintsDependOnEnclosingTemplate(NewFD))
10643 if (FunctionTemplate) {
10646 return FunctionTemplate;
10650 CompleteMemberSpecialization(NewFD,
Previous);
10658 if (getLangOpts().getOpenCLCompatibleVersion() >= 200) {
10660 QualType ElemTy = PipeTy->getElementType();
10662 Diag(Param->getTypeSpecStartLoc(), diag::err_reference_pipe_type );
10672 if (isDependentClassScopeExplicitSpecialization) {
10676 cast<CXXMethodDecl>(NewFD),
10677 HasExplicitTemplateArgs, TemplateArgs);
10678 CurContext->addDecl(NewSpec);
10679 AddToScope =
false;
10684 if (
const auto *
attr = NewFD->
getAttr<AvailabilityAttr>()) {
10685 if (NewFD->
hasAttr<ConstructorAttr>()) {
10686 Diag(
attr->getLocation(), diag::warn_availability_on_static_initializer)
10688 NewFD->
dropAttr<AvailabilityAttr>();
10690 if (NewFD->
hasAttr<DestructorAttr>()) {
10691 Diag(
attr->getLocation(), diag::warn_availability_on_static_initializer)
10693 NewFD->
dropAttr<AvailabilityAttr>();
10704 if (
const auto *NBA = NewFD->
getAttr<NoBuiltinAttr>())
10708 Diag(NBA->getLocation(),
10709 diag::err_attribute_no_builtin_on_defaulted_deleted_function)
10710 << NBA->getSpelling();
10713 Diag(NBA->getLocation(), diag::err_attribute_no_builtin_on_non_definition)
10714 << NBA->getSpelling();
10734 const auto *Method = dyn_cast<CXXMethodDecl>(FD);
10738 if (
const auto *SAttr =
Parent->getAttr<CodeSegAttr>()) {
10749 while ((
Parent = dyn_cast<CXXRecordDecl>(
Parent->getParent()))) {
10750 if (
const auto *SAttr =
Parent->getAttr<CodeSegAttr>()) {
10769 bool IsDefinition) {
10772 if (!FD->
hasAttr<SectionAttr>() && IsDefinition &&
10773 CodeSegStack.CurrentValue)
10774 return SectionAttr::CreateImplicit(
10775 getASTContext(), CodeSegStack.CurrentValue->getString(),
10777 SectionAttr::Declspec_allocate);
10842 auto *VD = dyn_cast<ValueDecl>(D);
10843 auto *PrevVD = dyn_cast<ValueDecl>(PrevDecl);
10844 return !VD || !PrevVD ||
10845 canFullyTypeCheckRedeclaration(VD, PrevVD, VD->getType(),
10846 PrevVD->getType());
10854 const auto *TA = FD->
getAttr<TargetAttr>();
10855 const auto *TVA = FD->
getAttr<TargetVersionAttr>();
10858 "MultiVersion candidate requires a target or target_version attribute");
10860 enum ErrType { Feature = 0, Architecture = 1 };
10867 << Architecture << ParseInfo.
CPU;
10870 for (
const auto &Feat : ParseInfo.
Features) {
10871 auto BareFeat = StringRef{Feat}.substr(1);
10872 if (Feat[0] ==
'-') {
10874 << Feature << (
"no-" + BareFeat).str();
10881 << Feature << BareFeat;
10889 TVA->getFeatures(Feats);
10890 for (
const auto &Feat : Feats) {
10893 << Feature << Feat;
10912 case attr::NonNull:
10913 case attr::NoThrow:
10922 const auto Diagnose = [FD, CausedFD, MVKind](
Sema &S,
const Attr *A) {
10923 S.
Diag(FD->
getLocation(), diag::err_multiversion_disallowed_other_attr)
10924 <<
static_cast<unsigned>(MVKind) << A;
10926 S.
Diag(CausedFD->getLocation(), diag::note_multiversioning_caused_here);
10931 switch (A->getKind()) {
10932 case attr::CPUDispatch:
10933 case attr::CPUSpecific:
10936 return Diagnose(S, A);
10940 return Diagnose(S, A);
10942 case attr::TargetVersion:
10944 return Diagnose(S, A);
10946 case attr::TargetClones:
10948 return Diagnose(S, A);
10952 return Diagnose(S, A);
10965 bool ConstexprSupported,
bool CLinkageMayDiffer) {
10966 enum DoesntSupport {
10973 DefaultedFuncs = 6,
10974 ConstexprFuncs = 7,
10975 ConstevalFuncs = 8,
10987 if (NoProtoDiagID.
getDiagID() != 0 && OldFD &&
10990 Diag(NoteCausedDiagIDAt.first, NoteCausedDiagIDAt.second);
10998 if (!TemplatesSupported &&
11000 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11003 if (
const auto *NewCXXFD = dyn_cast<CXXMethodDecl>(NewFD)) {
11004 if (NewCXXFD->isVirtual())
11005 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11008 if (isa<CXXConstructorDecl>(NewCXXFD))
11009 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11012 if (isa<CXXDestructorDecl>(NewCXXFD))
11013 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11018 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11022 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11026 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11027 << (NewFD->
isConsteval() ? ConstevalFuncs : ConstexprFuncs);
11030 const auto *NewType = cast<FunctionType>(NewQType);
11031 QualType NewReturnType = NewType->getReturnType();
11034 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11040 const auto *OldType = cast<FunctionType>(OldQType);
11044 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC())
11047 QualType OldReturnType = OldType->getReturnType();
11049 if (OldReturnType != NewReturnType)
11050 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << ReturnType;
11053 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << ConstexprSpec;
11056 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << InlineSpec;
11059 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) <<
Linkage;
11064 if (CheckEquivalentExceptionSpec(
11083 bool IsCPUSpecificCPUDispatchMVKind =
11087 if (CausesMV && OldFD &&
11095 if (OldFD && CausesMV && OldFD->
isUsed(
false))
11096 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_after_used);
11099 OldFD, NewFD, S.
PDiag(diag::err_multiversion_noproto),
11101 S.
PDiag(diag::note_multiversioning_caused_here)),
11103 S.
PDiag(diag::err_multiversion_doesnt_support)
11104 <<
static_cast<unsigned>(MVKind)),
11106 S.
PDiag(diag::err_multiversion_diff)),
11108 !IsCPUSpecificCPUDispatchMVKind,
11121 "Function lacks multiversion attribute");
11122 const auto *TA = FD->
getAttr<TargetAttr>();
11123 const auto *TVA = FD->
getAttr<TargetVersionAttr>();
11126 if ((TA && !TA->isDefaultVersion()) || (TVA && !TVA->isDefaultVersion()))
11154 bool &Redeclaration,
11157 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
11158 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
11159 const auto *OldTA = OldFD->
getAttr<TargetAttr>();
11160 const auto *OldTVA = OldFD->
getAttr<TargetVersionAttr>();
11163 if ((NewTA && !NewTA->isDefaultVersion() &&
11164 (!OldTA || OldTA->getFeaturesStr() == NewTA->getFeaturesStr())) ||
11165 (NewTVA && !NewTVA->isDefaultVersion() &&
11166 (!OldTVA || OldTVA->getName() == NewTVA->getName())))
11184 ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
11185 (NewTVA && NewTVA->isDefaultVersion() && !OldTVA))) {
11186 Redeclaration =
true;
11194 S.
Diag(NewFD->
getLocation(), diag::note_multiversioning_caused_here);
11202 OldTA->getFeaturesStr());
11206 NewTA->getFeaturesStr());
11209 if (OldParsed == NewParsed) {
11219 OldTVA->getFeatures(Feats);
11222 NewTVA->getFeatures(NewFeats);
11223 llvm::sort(NewFeats);
11225 if (Feats == NewFeats) {
11233 for (
const auto *FD : OldFD->
redecls()) {
11234 const auto *CurTA = FD->
getAttr<TargetAttr>();
11235 const auto *CurTVA = FD->
getAttr<TargetVersionAttr>();
11239 ((NewTA && (!CurTA || CurTA->isInherited())) ||
11240 (NewTVA && (!CurTVA || CurTVA->isInherited())))) {
11242 << (NewTA ? 0 : 2);
11243 S.
Diag(NewFD->
getLocation(), diag::note_multiversioning_caused_here);
11251 Redeclaration =
false;
11274 const CPUSpecificAttr *NewCPUSpec,
const TargetClonesAttr *NewClones,
11276 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
11277 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
11290 NewTA->getFeaturesStr());
11295 NewTVA->getFeatures(NewFeats);
11296 llvm::sort(NewFeats);
11299 bool UseMemberUsingDeclRules =
11302 bool MayNeedOverloadableChecks =
11311 if (MayNeedOverloadableChecks &&
11312 S.
IsOverload(NewFD, CurFD, UseMemberUsingDeclRules))
11317 NewFD->
addAttr(TargetVersionAttr::CreateImplicit(
11323 NewTVA = NewFD->
getAttr<TargetVersionAttr>();
11324 NewTVA->getFeatures(NewFeats);
11325 llvm::sort(NewFeats);
11329 switch (NewMVKind) {
11332 "Only target_clones can be omitted in subsequent declarations");
11335 const auto *CurTA = CurFD->
getAttr<TargetAttr>();
11336 if (CurTA->getFeaturesStr() == NewTA->getFeaturesStr()) {
11338 Redeclaration =
true;
11345 CurTA->getFeaturesStr());
11347 if (CurParsed == NewParsed) {
11356 const auto *CurTVA = CurFD->
getAttr<TargetVersionAttr>();
11357 if (CurTVA->getName() == NewTVA->getName()) {
11359 Redeclaration =
true;
11365 CurTVA->getFeatures(CurFeats);
11366 llvm::sort(CurFeats);
11368 if (CurFeats == NewFeats) {
11377 const auto *CurClones = CurFD->
getAttr<TargetClonesAttr>();
11378 Redeclaration =
true;
11382 if (CurClones && NewClones &&
11383 (CurClones->featuresStrs_size() != NewClones->featuresStrs_size() ||
11384 !std::equal(CurClones->featuresStrs_begin(),
11385 CurClones->featuresStrs_end(),
11386 NewClones->featuresStrs_begin()))) {
11397 const auto *CurCPUSpec = CurFD->
getAttr<CPUSpecificAttr>();
11398 const auto *CurCPUDisp = CurFD->
getAttr<CPUDispatchAttr>();
11403 CurFD->
hasAttr<CPUDispatchAttr>()) {
11404 if (CurCPUDisp->cpus_size() == NewCPUDisp->cpus_size() &&
11406 CurCPUDisp->cpus_begin(), CurCPUDisp->cpus_end(),
11407 NewCPUDisp->cpus_begin(),
11409 return Cur->getName() == New->getName();
11412 Redeclaration =
true;
11424 if (CurCPUSpec->cpus_size() == NewCPUSpec->cpus_size() &&
11426 CurCPUSpec->cpus_begin(), CurCPUSpec->cpus_end(),
11427 NewCPUSpec->cpus_begin(),
11429 return Cur->getName() == New->getName();
11432 Redeclaration =
true;
11440 if (CurII == NewII) {
11475 Redeclaration =
true;
11481 Redeclaration =
false;
11494 bool &Redeclaration,
NamedDecl *&OldDecl,
11496 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
11497 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
11498 const auto *NewCPUDisp = NewFD->
getAttr<CPUDispatchAttr>();
11499 const auto *NewCPUSpec = NewFD->
getAttr<CPUSpecificAttr>();
11500 const auto *NewClones = NewFD->
getAttr<TargetClonesAttr>();
11510 NewTVA->isDefaultVersion())) {
11511 S.
Diag(NewFD->
getLocation(), diag::err_multiversion_not_allowed_on_main);
11533 const auto *OldTVA = OldFD->
getAttr<TargetVersionAttr>();
11535 NewFD->
addAttr(TargetVersionAttr::CreateImplicit(
11541 Redeclaration =
true;
11553 S.
Diag(NewFD->
getLocation(), diag::err_multiversion_required_in_redecl)
11566 if (OldFD->
isUsed(
false)) {
11568 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_after_used);
11584 NewCPUSpec, NewClones, Redeclaration,
11607 bool IsMemberSpecialization,
11610 "Variably modified return types are not handled here");
11615 bool MergeTypeWithPrevious = !getLangOpts().CPlusPlus &&
11618 bool Redeclaration =
false;
11620 bool MayNeedOverloadableChecks =
false;
11631 if (shouldLinkPossiblyHiddenDecl(Candidate, NewFD)) {
11632 Redeclaration =
true;
11633 OldDecl = Candidate;
11636 MayNeedOverloadableChecks =
true;
11637 switch (CheckOverload(S, NewFD,
Previous, OldDecl,
11640 Redeclaration =
true;
11643 case Ovl_NonFunction:
11644 Redeclaration =
true;
11648 Redeclaration =
false;
11655 if (!Redeclaration &&
11660 Redeclaration =
true;
11661 OldDecl =
Previous.getFoundDecl();
11662 MergeTypeWithPrevious =
false;
11665 if (OldDecl->
hasAttr<OverloadableAttr>() ||
11666 NewFD->
hasAttr<OverloadableAttr>()) {
11667 if (IsOverload(NewFD, cast<FunctionDecl>(OldDecl),
false)) {
11668 MayNeedOverloadableChecks =
true;
11669 Redeclaration =
false;
11677 return Redeclaration;
11696 !MD->
isStatic() && !isa<CXXConstructorDecl>(MD) &&
11700 OldMD = dyn_cast_or_null<CXXMethodDecl>(OldDecl->
getAsFunction());
11701 if (!OldMD || !OldMD->
isStatic()) {
11711 if (!inTemplateInstantiation()) {
11715 AddConstLoc = getLocForEndOfToken(FTL.getRParenLoc());
11723 if (Redeclaration) {
11726 if (MergeFunctionDecl(NewFD, OldDecl, S, MergeTypeWithPrevious,
11729 return Redeclaration;
11736 dyn_cast<FunctionTemplateDecl>(OldDecl)) {
11737 auto *OldFD = OldTemplateDecl->getTemplatedDecl();
11740 assert(NewTemplateDecl &&
"Template/non-template mismatch");
11749 NewFD->
setAccess(OldTemplateDecl->getAccess());
11750 NewTemplateDecl->
setAccess(OldTemplateDecl->getAccess());
11755 if (IsMemberSpecialization &&
11758 assert(OldTemplateDecl->isMemberSpecialization());
11761 if (OldFD->isDeleted()) {
11763 assert(OldFD->getCanonicalDecl() == OldFD);
11765 OldFD->setDeletedAsWritten(
false);
11770 if (shouldLinkDependentDeclWithPrevious(NewFD, OldDecl)) {
11771 auto *OldFD = cast<FunctionDecl>(OldDecl);
11778 }
else if (!getLangOpts().
CPlusPlus && MayNeedOverloadableChecks &&
11779 !NewFD->
getAttr<OverloadableAttr>()) {
11783 return ND->hasAttr<OverloadableAttr>();
11785 "Non-redecls shouldn't happen without overloadable present");
11788 const auto *FD = dyn_cast<FunctionDecl>(ND);
11789 return FD && !FD->
hasAttr<OverloadableAttr>();
11792 if (OtherUnmarkedIter !=
Previous.end()) {
11794 diag::err_attribute_overloadable_multiple_unmarked_overloads);
11795 Diag((*OtherUnmarkedIter)->getLocation(),
11796 diag::note_attribute_overloadable_prev_overload)
11799 NewFD->
addAttr(OverloadableAttr::CreateImplicit(Context));
11803 if (LangOpts.OpenMP)
11804 ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(NewFD);
11811 CheckConstructor(Constructor);
11813 dyn_cast<CXXDestructorDecl>(NewFD)) {
11821 !Destructor->getThisType()->isDependentType()) {
11830 return Redeclaration;
11833 }
else if (
auto *Guide = dyn_cast<CXXDeductionGuideDecl>(NewFD)) {
11834 if (
auto *TD = Guide->getDescribedFunctionTemplate())
11835 CheckDeductionGuideTemplate(TD);
11840 Diag(Guide->getBeginLoc(), diag::err_deduction_guide_specialized)
11845 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(NewFD)) {
11846 if (!Method->isFunctionTemplateSpecialization() &&
11847 !Method->getDescribedFunctionTemplate() &&
11848 Method->isCanonicalDecl()) {
11849 AddOverriddenMethods(Method->getParent(), Method);
11855 diag::err_constrained_virtual_method);
11857 if (Method->isStatic())
11858 checkThisInStaticMemberFunctionType(Method);
11867 Diag(TRC->getBeginLoc(), diag::err_constrained_non_templated_function);
11871 ActOnConversionDeclarator(Conversion);
11875 CheckOverloadedOperatorDeclaration(NewFD)) {
11877 return Redeclaration;
11882 CheckLiteralOperatorDeclaration(NewFD)) {
11884 return Redeclaration;
11890 if (!CurContext->isRecord())
11891 CheckCXXDefaultArguments(NewFD);
11902 else if (!R.isPODType(Context) && !R->isVoidType() &&
11903 !R->isObjCObjectPointerType())
11904 Diag(NewFD->
getLocation(), diag::warn_return_value_udt) << NewFD << R;
11917 auto HasNoexcept = [&](
QualType T) ->
bool {
11922 T = RT->getPointeeType();
11923 else if (T->isAnyPointerType())
11924 T = T->getPointeeType();
11926 T = MPT->getPointeeType();
11928 if (FPT->isNothrow())
11934 bool AnyNoexcept = HasNoexcept(FPT->getReturnType());
11935 for (
QualType T : FPT->param_types())
11936 AnyNoexcept |= HasNoexcept(T);
11939 diag::warn_cxx17_compat_exception_spec_in_signature)
11943 if (!Redeclaration && LangOpts.CUDA)
11944 checkCUDATargetOverload(NewFD,
Previous);
11946 return Redeclaration;
11959 ? diag::err_static_main : diag::warn_static_main)
11966 SourceRange NoreturnRange(NoreturnLoc, getLocForEndOfToken(NoreturnLoc));
11967 Diag(NoreturnLoc, diag::ext_noreturn_main);
11968 Diag(NoreturnLoc, diag::note_main_remove_noreturn)
11978 if (getLangOpts().
OpenCL) {
11980 << FD->
hasAttr<OpenCLKernelAttr>();
11987 if (getLangOpts().HLSL)
11991 assert(T->
isFunctionType() &&
"function decl is not of function type");
12001 if (getLangOpts().GNUMode && !getLangOpts().CPlusPlus) {
12013 Diag(RTRange.
getBegin(), diag::note_main_change_return_type)
12035 if (isa<FunctionNoProtoType>(FT))
return;
12041 bool HasExtraParameters = (nparams > 3);
12053 HasExtraParameters =
false;
12055 if (HasExtraParameters) {
12068 for (
unsigned i = 0; i < nparams; ++i) {
12071 bool mismatch =
true;
12088 mismatch = !qs.
empty();
12117 if (T.isWindowsGNUEnvironment())
12122 if (T.isOSWindows() && T.getArch() == llvm::Triple::x86)
12130 assert(T->
isFunctionType() &&
"function decl is not of function type");
12139 if (FD->
getName() !=
"DllMain")
12143 if (!hasExplicitCallingConv(T)) {
12164 auto &
TargetInfo = getASTContext().getTargetInfo();
12166 switch (Triple.getEnvironment()) {
12170 case llvm::Triple::EnvironmentType::Compute:
12171 if (!FD->
hasAttr<HLSLNumThreadsAttr>()) {
12173 << Triple.getEnvironmentName();
12179 for (
const auto *Param : FD->
parameters()) {
12184 Diag(Param->getLocation(), diag::note_previous_decl) << Param;
12201 if (Init->isValueDependent()) {
12202 assert(Init->containsErrors() &&
12203 "Dependent code should only occur in error-recovery path.");
12206 const Expr *Culprit;
12207 if (Init->isConstantInitializer(Context,
false, &Culprit))
12209 Diag(Culprit->
getExprLoc(), diag::err_init_element_not_constant)
12217 class SelfReferenceChecker
12223 bool isReferenceType;
12231 SelfReferenceChecker(
Sema &S,
Decl *OrigDecl) : Inherited(S.Context),
12232 S(S), OrigDecl(OrigDecl) {
12235 isReferenceType =
false;
12236 isInitList =
false;
12237 if (
ValueDecl *VD = dyn_cast<ValueDecl>(OrigDecl)) {
12238 isPODType = VD->getType().isPODType(S.
Context);
12240 isReferenceType = VD->getType()->isReferenceType();
12247 void CheckExpr(
Expr *E) {
12256 InitFieldIndex.push_back(0);
12257 for (
auto *Child : InitList->
children()) {
12258 CheckExpr(cast<Expr>(Child));
12259 ++InitFieldIndex.back();
12261 InitFieldIndex.pop_back();
12266 bool CheckInitListMemberExpr(
MemberExpr *E,
bool CheckReference) {
12269 bool ReferenceField =
false;
12273 FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
12276 Fields.push_back(FD);
12278 ReferenceField =
true;
12279 Base = ME->getBase()->IgnoreParenImpCasts();
12284 if (!DRE || DRE->
getDecl() != OrigDecl)
12288 if (CheckReference && !ReferenceField)
12293 for (
const FieldDecl *I : llvm::reverse(Fields))
12294 UsedFieldIndex.push_back(I->getFieldIndex());
12299 for (
auto UsedIter = UsedFieldIndex.begin(),
12300 UsedEnd = UsedFieldIndex.end(),
12301 OrigIter = InitFieldIndex.begin(),
12302 OrigEnd = InitFieldIndex.end();
12303 UsedIter != UsedEnd && OrigIter != OrigEnd; ++UsedIter, ++OrigIter) {
12304 if (*UsedIter < *OrigIter)
12306 if (*UsedIter > *OrigIter)
12311 HandleDeclRefExpr(DRE);
12318 void HandleValue(
Expr *E) {
12320 if (
DeclRefExpr* DRE = dyn_cast<DeclRefExpr>(E)) {
12321 HandleDeclRefExpr(DRE);
12326 Visit(CO->getCond());
12327 HandleValue(CO->getTrueExpr());
12328 HandleValue(CO->getFalseExpr());
12333 dyn_cast<BinaryConditionalOperator>(E)) {
12334 Visit(BCO->getCond());
12335 HandleValue(BCO->getFalseExpr());
12340 HandleValue(OVE->getSourceExpr());
12345 if (BO->getOpcode() == BO_Comma) {
12346 Visit(BO->getLHS());
12347 HandleValue(BO->getRHS());
12352 if (isa<MemberExpr>(E)) {
12354 if (CheckInitListMemberExpr(cast<MemberExpr>(E),
12362 if (!isa<FieldDecl>(ME->getMemberDecl()))
12364 Base = ME->getBase()->IgnoreParenImpCasts();
12367 HandleDeclRefExpr(DRE);
12377 if (isReferenceType)
12378 HandleDeclRefExpr(E);
12387 Inherited::VisitImplicitCastExpr(E);
12392 if (CheckInitListMemberExpr(E,
true ))
12402 bool Warn = (MD && !MD->
isStatic());
12405 if (!isa<FieldDecl>(ME->getMemberDecl()))
12407 Base = ME->getBase()->IgnoreParenImpCasts();
12412 HandleDeclRefExpr(DRE);
12424 if (isa<UnresolvedLookupExpr>(Callee))
12425 return Inherited::VisitCXXOperatorCallExpr(E);
12429 HandleValue(Arg->IgnoreParenImpCasts());
12446 Inherited::VisitUnaryOperator(E);
12454 if (
InitListExpr *ILE = dyn_cast<InitListExpr>(ArgExpr))
12455 if (ILE->getNumInits() == 1)
12456 ArgExpr = ILE->getInit(0);
12458 if (ICE->getCastKind() == CK_NoOp)
12459 ArgExpr = ICE->getSubExpr();
12460 HandleValue(ArgExpr);
12463 Inherited::VisitCXXConstructExpr(E);
12469 HandleValue(E->
getArg(0));
12473 Inherited::VisitCallExpr(E);
12478 HandleValue(E->
getLHS());
12483 Inherited::VisitBinaryOperator(E);
12496 if (OrigDecl != ReferenceDecl)
return;
12498 if (isReferenceType) {
12499 diag = diag::warn_uninit_self_reference_in_reference_init;
12500 }
else if (cast<VarDecl>(OrigDecl)->isStaticLocal()) {
12501 diag = diag::warn_static_self_reference_in_init;
12502 }
else if (isa<TranslationUnitDecl>(OrigDecl->
getDeclContext()) ||
12505 diag = diag::warn_uninit_self_reference_in_init;
12519 static void CheckSelfReference(
Sema &S,
Decl* OrigDecl,
Expr *E,
12523 if (isa<ParmVarDecl>(OrigDecl))
12530 if (!DirectInit && !cast<VarDecl>(OrigDecl)->getType()->
isRecordType())
12532 if (ICE->getCastKind() == CK_LValueToRValue)
12533 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()))
12534 if (DRE->
getDecl() == OrigDecl)
12537 SelfReferenceChecker(S, OrigDecl).CheckExpr(E);
12544 struct VarDeclOrName {
12550 return VN.VDecl ?
Diag << VN.VDecl :
Diag << VN.Name;
12560 bool IsInitCapture = !VDecl;
12562 "init captures are expected to be deduced prior to initialization");
12564 VarDeclOrName VN{VDecl, Name};
12567 assert(Deduced &&
"deduceVarTypeFromInitializer for non-deduced type");
12571 assert(VDecl &&
"no init for init capture deduction?");
12575 if (!isa<DeducedTemplateSpecializationType>(Deduced) ||
12586 DeduceInits = Init;
12589 if (
auto *PL = dyn_cast_or_null<ParenListExpr>(Init))
12590 DeduceInits = PL->exprs();
12593 if (isa<DeducedTemplateSpecializationType>(Deduced)) {
12594 assert(VDecl &&
"non-auto type for init capture deduction?");
12600 return DeduceTemplateSpecializationFromInitializer(TSI, Entity,
Kind,
12605 if (
auto *IL = dyn_cast<InitListExpr>(Init))
12606 DeduceInits = IL->inits();
12610 if (DeduceInits.empty()) {
12613 Diag(Init->getBeginLoc(), IsInitCapture
12614 ? diag::err_init_capture_no_expression
12615 : diag::err_auto_var_init_no_expression)
12616 << VN <<
Type << Range;
12620 if (DeduceInits.size() > 1) {
12621 Diag(DeduceInits[1]->getBeginLoc(),
12622 IsInitCapture ? diag::err_init_capture_multiple_expressions
12623 : diag::err_auto_var_init_multiple_expressions)
12624 << VN <<
Type << Range;
12628 Expr *DeduceInit = DeduceInits[0];
12629 if (
DirectInit && isa<InitListExpr>(DeduceInit)) {
12630 Diag(Init->getBeginLoc(), IsInitCapture
12631 ? diag::err_init_capture_paren_braces
12632 : diag::err_auto_var_init_paren_braces)
12633 << isa<InitListExpr>(Init) << VN <<
Type << Range;
12638 bool DefaultedAnyToId =
false;
12639 if (getLangOpts().DebuggerCastResultToId &&
12640 Init->getType() == Context.
UnknownAnyTy && !IsInitCapture) {
12642 if (Result.isInvalid()) {
12645 Init = Result.get();
12646 DefaultedAnyToId =
true;
12652 if (VDecl && isa<DecompositionDecl>(VDecl) &&
12656 Type.getQualifiers());
12662 if (Result != TDK_Success && Result != TDK_AlreadyDiagnosed) {
12663 if (!IsInitCapture)
12664 DiagnoseAutoDeductionFailure(VDecl, DeduceInit);
12665 else if (isa<InitListExpr>(Init))
12666 Diag(Range.getBegin(),
12667 diag::err_init_capture_deduction_failure_from_init_list)
12673 Diag(Range.getBegin(), diag::err_init_capture_deduction_failure)
12685 if (!inTemplateInstantiation() && !DefaultedAnyToId && !IsInitCapture &&
12688 Diag(Loc, diag::warn_auto_var_is_id) << VN << Range;
12696 assert(!Init || !Init->containsErrors());
12709 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(VDecl))
12712 if (getLangOpts().
OpenCL)
12713 deduceOpenCLAddressSpace(VDecl);
12720 MergeVarDeclTypes(VDecl, Old,
false);
12724 CheckVariableDeclarationType(VDecl);
12730 if (
auto *EWC = dyn_cast<ExprWithCleanups>(Init))
12731 Init = EWC->getSubExpr();
12733 if (
auto *CE = dyn_cast<ConstantExpr>(Init))
12734 Init = CE->getSubExpr();
12736 QualType InitType = Init->getType();
12739 "shouldn't be called if type doesn't have a non-trivial C struct");
12740 if (
auto *ILE = dyn_cast<InitListExpr>(Init)) {
12741 for (
auto *I : ILE->inits()) {
12742 if (!I->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion() &&
12743 !I->getType().hasNonTrivialToPrimitiveCopyCUnion())
12746 checkNonTrivialCUnionInInitializer(I, SL.
isValid() ? SL : Loc);
12751 if (isa<ImplicitValueInitExpr>(Init)) {
12753 checkNonTrivialCUnion(InitType, Loc, NTCUC_DefaultInitializedObject,
12761 checkNonTrivialCUnion(InitType, Loc, NTCUC_CopyInit, NTCUK_Copy);
12767 bool shouldIgnoreForRecordTriviality(
const FieldDecl *FD) {
12773 return FD->
hasAttr<UnavailableAttr>();
12776 struct DiagNonTrivalCUnionDefaultInitializeVisitor
12783 DiagNonTrivalCUnionDefaultInitializeVisitor(
12786 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
12789 const FieldDecl *FD,
bool InNonTrivialUnion) {
12792 InNonTrivialUnion);
12793 return Super::visitWithKind(PDIK, QT, FD, InNonTrivialUnion);
12797 bool InNonTrivialUnion) {
12798 if (InNonTrivialUnion)
12800 << 1 << 0 << QT << FD->
getName();
12804 if (InNonTrivialUnion)
12806 << 1 << 0 << QT << FD->
getName();
12812 if (OrigLoc.isValid()) {
12813 bool IsUnion =
false;
12814 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
12815 IsUnion = OrigRD->isUnion();
12816 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
12817 << 0 << OrigTy << IsUnion << UseContext;
12821 InNonTrivialUnion =
true;
12824 if (InNonTrivialUnion)
12829 if (!shouldIgnoreForRecordTriviality(FD))
12830 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
12843 struct DiagNonTrivalCUnionDestructedTypeVisitor
12848 DiagNonTrivalCUnionDestructedTypeVisitor(
12851 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
12854 const FieldDecl *FD,
bool InNonTrivialUnion) {
12857 InNonTrivialUnion);
12858 return Super::visitWithKind(DK, QT, FD, InNonTrivialUnion);
12862 bool InNonTrivialUnion) {
12863 if (InNonTrivialUnion)
12865 << 1 << 1 << QT << FD->
getName();
12869 if (InNonTrivialUnion)
12871 << 1 << 1 << QT << FD->
getName();
12877 if (OrigLoc.isValid()) {
12878 bool IsUnion =
false;
12879 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
12880 IsUnion = OrigRD->isUnion();
12881 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
12882 << 1 << OrigTy << IsUnion << UseContext;
12886 InNonTrivialUnion =
true;
12889 if (InNonTrivialUnion)
12894 if (!shouldIgnoreForRecordTriviality(FD))
12895 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
12900 bool InNonTrivialUnion) {}
12910 struct DiagNonTrivalCUnionCopyVisitor
12917 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
12920 const FieldDecl *FD,
bool InNonTrivialUnion) {
12923 InNonTrivialUnion);
12924 return Super::visitWithKind(PCK, QT, FD, InNonTrivialUnion);
12928 bool InNonTrivialUnion) {
12929 if (InNonTrivialUnion)
12931 << 1 << 2 << QT << FD->
getName();
12935 if (InNonTrivialUnion)
12937 << 1 << 2 << QT << FD->
getName();
12943 if (OrigLoc.isValid()) {
12944 bool IsUnion =
false;
12945 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
12946 IsUnion = OrigRD->isUnion();
12947 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
12948 << 2 << OrigTy << IsUnion << UseContext;
12952 InNonTrivialUnion =
true;
12955 if (InNonTrivialUnion)
12960 if (!shouldIgnoreForRecordTriviality(FD))
12961 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
12965 const FieldDecl *FD,
bool InNonTrivialUnion) {}
12968 bool InNonTrivialUnion) {}
12982 unsigned NonTrivialKind) {
12986 "shouldn't be called if type doesn't have a non-trivial C union");
12988 if ((NonTrivialKind & NTCUK_Init) &&
12990 DiagNonTrivalCUnionDefaultInitializeVisitor(QT, Loc, UseContext, *
this)
12991 .
visit(QT,
nullptr,
false);
12992 if ((NonTrivialKind & NTCUK_Destruct) &&
12994 DiagNonTrivalCUnionDestructedTypeVisitor(QT, Loc, UseContext, *
this)
12995 .visit(QT,
nullptr,
false);
12997 DiagNonTrivalCUnionCopyVisitor(QT, Loc, UseContext, *
this)
12998 .visit(QT,
nullptr,
false);
13008 CorrectDelayedTyposInExpr(Init, dyn_cast_or_null<VarDecl>(RealDecl));
13012 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(RealDecl)) {
13014 Diag(Method->getLocation(), diag::err_member_function_initialization)
13015 << Method->getDeclName() << Init->getSourceRange();
13016 Method->setInvalidDecl();
13020 VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
13022 assert(!isa<FieldDecl>(RealDecl) &&
"field init shouldn't get here");
13033 ExprResult Res = CorrectDelayedTyposInExpr(Init, VDecl);
13048 if (DeduceVariableDeclarationType(VDecl,
DirectInit, Init))
13054 Diag(VDecl->
getLocation(), diag::err_attribute_dllimport_data_definition);
13075 BaseDeclType = Array->getElementType();
13076 if (RequireCompleteType(VDecl->
getLocation(), BaseDeclType,
13077 diag::err_typecheck_decl_incomplete_type)) {
13084 diag::err_abstract_type_in_decl,
13085 AbstractVariableType))
13091 if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
13095 !isa<VarTemplateSpecializationDecl>(VDecl)) {
13104 if (Def != VDecl &&
13107 checkVarDeclRedefinition(Def, VDecl))
13124 Diag(Init->getExprLoc(), diag::err_static_data_member_reinitialization)
13127 diag::note_previous_initializer)
13133 setFunctionHasBranchProtectedScope();
13135 if (DiagnoseUnexpandedParameterPack(Init, UPPC_Initializer)) {
13150 if (VDecl->
hasAttr<LoaderUninitializedAttr>()) {
13151 Diag(VDecl->
getLocation(), diag::err_loader_uninitialized_cant_init);
13165 if (Result.isInvalid()) {
13169 Init = Result.get();
13173 ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init);
13174 bool IsParenListInit =
false;
13186 for (
size_t Idx = 0; Idx < Args.size(); ++Idx) {
13188 Args[Idx], VDecl,
true,
13191 return Init.Failed() ?
ExprError() : E;
13195 }
else if (Res.
get() != Args[Idx]) {
13196 Args[Idx] = Res.
get();
13206 if (Result.isInvalid()) {
13210 CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), Args);
13216 Init = Result.getAs<
Expr>();
13217 IsParenListInit = !InitSeq.
steps().empty() &&
13226 if (getLangOpts().CPlusPlus)
13229 CheckSelfReference(*
this, RealDecl, Init,
DirectInit);
13241 if (VDecl->
hasAttr<BlocksAttr>())
13242 checkRetainCycles(VDecl, Init);
13254 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
13255 Init->getBeginLoc()))
13256 FSI->markSafeWeakUse(Init);
13273 if (Result.isInvalid()) {
13277 Init = Result.get();
13290 CheckForConstantInitializer(Init, DclT);
13299 CheckForConstantInitializer(Init, DclT);
13306 isa<InitListExpr>(Init)) {
13307 const Expr *Culprit;
13308 if (!Init->isConstantInitializer(Context,
false, &Culprit)) {
13310 diag::ext_aggregate_init_not_constant)
13315 if (
auto *E = dyn_cast<ExprWithCleanups>(Init))
13316 if (
auto *BE = dyn_cast<BlockExpr>(E->getSubExpr()->
IgnoreParens()))
13318 BE->getBlockDecl()->setCanAvoidCopyToHeap();
13353 << Init->getSourceRange();
13364 else if (Init->isValueDependent())
13366 else if (Init->isIntegerConstantExpr(Context, &Loc))
13368 else if (Init->getType()->isScopedEnumeralType() &&
13369 Init->isCXX11ConstantExpr(Context))
13371 else if (Init->isEvaluatable(Context)) {
13374 Diag(Loc, diag::ext_in_class_initializer_non_constant)
13375 << Init->getSourceRange();
13379 Diag(Loc, diag::err_in_class_initializer_non_constant)
13380 << Init->getSourceRange();
13390 diag::ext_in_class_initializer_float_type_cxx11)
13391 << DclT << Init->getSourceRange();
13393 diag::note_in_class_initializer_float_type_cxx11)
13396 Diag(VDecl->
getLocation(), diag::ext_in_class_initializer_float_type)
13397 << DclT << Init->getSourceRange();
13399 if (!Init->isValueDependent() && !Init->isEvaluatable(Context)) {
13400 Diag(Init->getExprLoc(), diag::err_in_class_initializer_non_constant)
13401 << Init->getSourceRange();
13408 Diag(VDecl->
getLocation(), diag::err_in_class_initializer_literal_type)
13409 << DclT << Init->getSourceRange()
13415 << DclT << Init->getSourceRange();
13443 CheckForConstantInitializer(Init, DclT);
13446 QualType InitType = Init->getType();
13447 if (!InitType.
isNull() &&
13450 checkNonTrivialCUnionInInitializer(Init, Init->getExprLoc());
13466 if (CXXDirectInit) {
13467 assert(
DirectInit &&
"Call-style initializer must be direct init.");
13475 if (LangOpts.OpenMP &&
13478 DeclsToCheckForDeferredDiags.insert(VDecl);
13479 CheckCompleteVariableDeclaration(VDecl);
13491 VarDecl *VD = dyn_cast<VarDecl>(D);
13495 if (
auto *DD = dyn_cast<DecompositionDecl>(D))
13496 for (
auto *BD : DD->bindings())
13497 BD->setInvalidDecl();
13511 diag::err_typecheck_decl_incomplete_type)) {
13517 if (RequireNonAbstractType(VD->
getLocation(), Ty,
13518 diag::err_abstract_type_in_decl,
13519 AbstractVariableType)) {
13533 if (
VarDecl *Var = dyn_cast<VarDecl>(RealDecl)) {
13537 if (isa<DecompositionDecl>(RealDecl)) {
13538 Diag(Var->getLocation(), diag::err_decomp_decl_requires_init) << Var;
13539 Var->setInvalidDecl();
13544 DeduceVariableDeclarationType(Var,
false,
nullptr))
13553 if (Var->isConstexpr() && !Var->isThisDeclarationADefinition() &&
13554 !Var->isThisDeclarationADemotedDefinition()) {
13555 if (Var->isStaticDataMember()) {
13560 Diag(Var->getLocation(),
13561 diag::err_constexpr_static_mem_var_requires_init)
13563 Var->setInvalidDecl();
13567 Diag(Var->getLocation(), diag::err_invalid_constexpr_var_decl);
13568 Var->setInvalidDecl();
13575 if (!Var->isInvalidDecl() &&
13577 Var->getStorageClass() !=
SC_Extern && !Var->getInit()) {
13578 bool HasConstExprDefaultConstructor =
false;
13579 if (
CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) {
13580 for (
auto *Ctor : RD->ctors()) {
13581 if (Ctor->isConstexpr() && Ctor->getNumParams() == 0 &&
13582 Ctor->getMethodQualifiers().getAddressSpace() ==
13584 HasConstExprDefaultConstructor =
true;
13588 if (!HasConstExprDefaultConstructor) {
13589 Diag(Var->getLocation(), diag::err_opencl_constant_no_init);
13590 Var->setInvalidDecl();
13595 if (!Var->isInvalidDecl() && RealDecl->
hasAttr<LoaderUninitializedAttr>()) {
13596 if (Var->getStorageClass() ==
SC_Extern) {
13597 Diag(Var->getLocation(), diag::err_loader_uninitialized_extern_decl)
13599 Var->setInvalidDecl();
13602 if (RequireCompleteType(Var->getLocation(), Var->getType(),
13603 diag::err_typecheck_decl_incomplete_type)) {
13604 Var->setInvalidDecl();
13607 if (
CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) {
13608 if (!RD->hasTrivialDefaultConstructor()) {
13609 Diag(Var->getLocation(), diag::err_loader_uninitialized_trivial_ctor);
13610 Var->setInvalidDecl();
13620 Var->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion())
13621 checkNonTrivialCUnion(Var->getType(), Var->getLocation(),
13622 NTCUC_DefaultInitializedObject, NTCUK_Init);
13627 if (!Var->isStaticDataMember() || !Var->getAnyInitializer())
13643 !Var->hasLinkage() && !Var->isInvalidDecl() &&
13644 RequireCompleteType(Var->getLocation(),
Type,
13645 diag::err_typecheck_decl_incomplete_type))
13646 Var->setInvalidDecl();
13650 RequireNonAbstractType(Var->getLocation(),
Type,
13651 diag::err_abstract_type_in_decl,
13652 AbstractVariableType))
13653 Var->setInvalidDecl();
13656 Diag(Var->getLocation(), diag::warn_private_extern);
13657 Diag(Var->getLocation(), diag::note_private_extern);
13661 !Var->isInvalidDecl() && !getLangOpts().
CPlusPlus)
13662 ExternalDeclarations.push_back(Var);
13672 if (!Var->isInvalidDecl()) {
13675 if (RequireCompleteSizedType(
13676 Var->getLocation(), ArrayT->getElementType(),
13677 diag::err_array_incomplete_or_sizeless_type))
13678 Var->setInvalidDecl();
13679 }
else if (Var->getStorageClass() ==
SC_Static) {
13689 if (Var->isFirstDecl())
13690 RequireCompleteType(Var->getLocation(),
Type,
13691 diag::ext_typecheck_decl_incomplete_type);
13696 if (!Var->isInvalidDecl())
13697 TentativeDefinitions.push_back(Var);
13704 if (Var->isConstexpr())
13705 Diag(Var->getLocation(), diag::err_constexpr_var_requires_const_init)
13708 Diag(Var->getLocation(),
13709 diag::err_typecheck_incomplete_array_needs_initializer);
13710 Var->setInvalidDecl();
13717 Diag(Var->getLocation(), diag::err_reference_var_requires_init)
13718 << Var <<
SourceRange(Var->getLocation(), Var->getLocation());
13727 if (Var->isInvalidDecl())
13730 if (!Var->hasAttr<AliasAttr>()) {
13731 if (RequireCompleteType(Var->getLocation(),
13733 diag::err_typecheck_decl_incomplete_type)) {
13734 Var->setInvalidDecl();
13742 if (RequireNonAbstractType(Var->getLocation(),
Type,
13743 diag::err_abstract_type_in_decl,
13744 AbstractVariableType)) {
13745 Var->setInvalidDecl();
13759 if (getLangOpts().
CPlusPlus && Var->hasLocalStorage()) {
13762 CXXRecordDecl *CXXRecord = cast<CXXRecordDecl>(Record->getDecl());
13766 if (!CXXRecord->isPOD())
13767 setFunctionHasBranchProtectedScope();
13772 if (getLangOpts().
OpenCL &&
13797 Var->setInit(MaybeCreateExprWithCleanups(Init.get()));
13800 }
else if (Init.isInvalid()) {
13804 CreateRecoveryExpr(Var->getLocation(), Var->getLocation(), {});
13809 CheckCompleteVariableDeclaration(Var);
13818 VarDecl *VD = dyn_cast<VarDecl>(D);
13877 const char *PrevSpec;
13880 getPrintingPolicy());
13888 Decl *Var = ActOnDeclarator(S, D);
13889 cast<VarDecl>(Var)->setCXXForRangeDecl(
true);
13890 FinalizeDeclaration(Var);
13891 return ActOnDeclStmt(FinalizeDeclaratorGroup(S, DS, Var), IdentLoc,
13897 if (
var->isInvalidDecl())
return;
13899 MaybeAddCUDAConstantAttr(
var);
13901 if (getLangOpts().
OpenCL) {
13904 if (
var->getTypeSourceInfo()->getType()->isBlockPointerType() &&
13906 Diag(
var->getLocation(), diag::err_opencl_invalid_block_declaration)
13908 var->setInvalidDecl();
13915 if (getLangOpts().ObjC &&
13916 var->hasLocalStorage()) {
13917 switch (
var->getType().getObjCLifetime()) {
13925 setFunctionHasBranchProtectedScope();
13930 if (
var->hasLocalStorage() &&
13932 setFunctionHasBranchProtectedScope();
13939 if (
var->isThisDeclarationADefinition() &&
13940 var->getDeclContext()->getRedeclContext()->isFileContext() &&
13941 var->isExternallyVisible() &&
var->hasLinkage() &&
13942 !
var->isInline() && !
var->getDescribedVarTemplate() &&
13943 !isa<VarTemplatePartialSpecializationDecl>(
var) &&
13945 !getDiagnostics().isIgnored(diag::warn_missing_variable_declarations,
13946 var->getLocation())) {
13953 Diag(
var->getLocation(), diag::warn_missing_variable_declarations) <<
var;
13954 Diag(
var->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage)
13960 std::optional<bool> CacheHasConstInit;
13961 const Expr *CacheCulprit =
nullptr;
13962 auto checkConstInit = [&]()
mutable {
13963 if (!CacheHasConstInit)
13964 CacheHasConstInit =
var->getInit()->isConstantInitializer(
13965 Context,
var->getType()->isReferenceType(), &CacheCulprit);
13966 return *CacheHasConstInit;
13970 if (
var->getType().isDestructedType()) {
13974 Diag(
var->getLocation(), diag::err_thread_nontrivial_dtor);
13976 Diag(
var->getLocation(), diag::note_use_thread_local);
13977 }
else if (getLangOpts().
CPlusPlus &&
var->hasInit()) {
13978 if (!checkConstInit()) {
13986 Diag(
var->getLocation(), diag::note_use_thread_local);
13992 if (!
var->getType()->isStructureType() &&
var->hasInit() &&
13993 isa<InitListExpr>(
var->getInit())) {
13994 const auto *ILE = cast<InitListExpr>(
var->getInit());
13995 unsigned NumInits = ILE->getNumInits();
13997 for (
unsigned I = 0; I < NumInits; ++I) {
13998 const auto *Init = ILE->getInit(I);
14001 const auto *SL = dyn_cast<StringLiteral>(Init->IgnoreImpCasts());
14005 unsigned NumConcat = SL->getNumConcatenated();
14009 if (NumConcat == 2 && !SL->getBeginLoc().isMacroID()) {
14010 bool OnlyOneMissingComma =
true;
14011 for (
unsigned J = I + 1; J < NumInits; ++J) {
14012 const auto *Init = ILE->getInit(J);
14015 const auto *SLJ = dyn_cast<StringLiteral>(Init->IgnoreImpCasts());
14016 if (!SLJ || SLJ->getNumConcatenated() > 1) {
14017 OnlyOneMissingComma =
false;
14022 if (OnlyOneMissingComma) {
14024 for (
unsigned i = 0; i < NumConcat - 1; ++i)
14026 PP.getLocForEndOfToken(SL->getStrTokenLoc(i)),
","));
14028 Diag(SL->getStrTokenLoc(1),
14029 diag::warn_concatenated_literal_array_init)
14031 Diag(SL->getBeginLoc(),
14032 diag::note_concatenated_string_literal_silence);
14043 if (
var->hasAttr<BlocksAttr>())
14044 getCurFunction()->addByrefBlockVar(
var);
14047 bool GlobalStorage =
var->hasGlobalStorage();
14048 bool IsGlobal = GlobalStorage && !
var->isStaticLocal();
14050 bool HasConstInit =
true;
14053 if (getLangOpts().
CPlusPlus && !
type->isDependentType() && Init &&
14054 !Init->isValueDependent() &&
14055 (GlobalStorage ||
var->isConstexpr() ||
14056 var->mightBeUsableInConstantExpressions(Context))) {
14068 HasConstInit = checkConstInit();
14072 if (HasConstInit) {
14073 (void)
var->checkForConstantInitialization(Notes);
14075 }
else if (CacheCulprit) {
14076 Notes.emplace_back(CacheCulprit->
getExprLoc(),
14077 PDiag(diag::note_invalid_subexpr_in_const_expr));
14082 HasConstInit =
var->checkForConstantInitialization(Notes);
14085 if (HasConstInit) {
14087 }
else if (
var->isConstexpr()) {
14091 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
14092 diag::note_invalid_subexpr_in_const_expr) {
14093 DiagLoc = Notes[0].first;
14096 Diag(DiagLoc, diag::err_constexpr_var_requires_const_init)
14097 <<
var << Init->getSourceRange();
14098 for (
unsigned I = 0, N = Notes.size(); I != N; ++I)
14099 Diag(Notes[I].first, Notes[I].second);
14100 }
else if (GlobalStorage &&
var->hasAttr<ConstInitAttr>()) {
14101 auto *
Attr =
var->getAttr<ConstInitAttr>();
14102 Diag(
var->getLocation(), diag::err_require_constant_init_failed)
14103 << Init->getSourceRange();
14106 for (
auto &it : Notes)
14107 Diag(it.first, it.second);
14108 }
else if (IsGlobal &&
14109 !getDiagnostics().isIgnored(diag::warn_global_constructor,
14110 var->getLocation())) {
14119 if (!checkConstInit())
14120 Diag(
var->getLocation(), diag::warn_global_constructor)
14121 << Init->getSourceRange();
14127 if (GlobalStorage &&
var->isThisDeclarationADefinition() &&
14128 !inTemplateInstantiation()) {
14131 if (
var->getType().isConstQualified()) {
14133 Stack = &ConstSegStack;
14135 Stack = &BSSSegStack;
14138 }
else if (
var->hasInit() && HasConstInit) {
14139 Stack = &DataSegStack;
14142 Stack = &BSSSegStack;
14145 if (
const SectionAttr *SA =
var->getAttr<SectionAttr>()) {
14148 UnifySection(SA->getName(), SectionFlags,
var);
14149 }
else if (Stack->CurrentValue) {
14151 auto SectionName = Stack->CurrentValue->getString();
14152 var->addAttr(SectionAttr::CreateImplicit(
14153 Context, SectionName, Stack->CurrentPragmaLocation,
14155 if (UnifySection(SectionName, SectionFlags,
var))
14156 var->dropAttr<SectionAttr>();
14162 if (CurInitSeg &&
var->getInit())
14163 var->addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(),
14169 if (!getLangOpts().CPlusPlus) {
14178 if (!
type->isDependentType())
14188 if (
auto *DD = dyn_cast<DecompositionDecl>(
var))
14189 CheckCompleteDecompositionDeclaration(DD);
14201 !FD->
hasAttr<DLLExportStaticLocalAttr>() &&
14202 !FD->
hasAttr<DLLImportStaticLocalAttr>()) {
14211 auto *NewAttr = cast<InheritableAttr>(A->clone(getASTContext()));
14212 NewAttr->setInherited(
true);
14214 }
else if (
Attr *A = FD->
getAttr<DLLExportStaticLocalAttr>()) {
14215 auto *NewAttr = DLLExportAttr::CreateImplicit(getASTContext(), *A);
14216 NewAttr->setInherited(
true);
14221 if (!FD->
hasAttr<DLLExportAttr>())
14224 }
else if (
Attr *A = FD->
getAttr<DLLImportStaticLocalAttr>()) {
14225 auto *NewAttr = DLLImportAttr::CreateImplicit(getASTContext(), *A);
14226 NewAttr->setInherited(
true);
14255 ParsingInitForAutoVars.erase(ThisDecl);
14257 VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDecl);
14263 !inTemplateInstantiation() && !VD->
hasAttr<SectionAttr>()) {
14264 if (PragmaClangBSSSection.Valid)
14265 VD->
addAttr(PragmaClangBSSSectionAttr::CreateImplicit(
14266 Context, PragmaClangBSSSection.SectionName,
14267 PragmaClangBSSSection.PragmaLocation,
14269 if (PragmaClangDataSection.Valid)
14270 VD->
addAttr(PragmaClangDataSectionAttr::CreateImplicit(
14271 Context, PragmaClangDataSection.SectionName,
14272 PragmaClangDataSection.PragmaLocation,
14274 if (PragmaClangRodataSection.Valid)
14275 VD->
addAttr(PragmaClangRodataSectionAttr::CreateImplicit(
14276 Context, PragmaClangRodataSection.SectionName,
14277 PragmaClangRodataSection.PragmaLocation,
14279 if (PragmaClangRelroSection.Valid)
14280 VD->
addAttr(PragmaClangRelroSectionAttr::CreateImplicit(
14281 Context, PragmaClangRelroSection.SectionName,
14282 PragmaClangRelroSection.PragmaLocation,
14286 if (
auto *DD = dyn_cast<DecompositionDecl>(ThisDecl)) {
14287 for (
auto *BD : DD->bindings()) {
14288 FinalizeDeclaration(BD);
14295 CheckStaticLocalForDllExport(VD);
14298 CheckThreadLocalForLargeAlignment(VD);
14305 if (getLangOpts().
CUDA)
14306 checkAllowedCUDAInitializer(VD);
14312 if (
const auto *IA = dyn_cast_or_null<DLLImportAttr>(DLLAttr)) {
14319 bool IsClassTemplateMember =
14320 isa<ClassTemplatePartialSpecializationDecl>(Context) ||
14321 Context->getDescribedClassTemplate();
14324 IsClassTemplateMember
14325 ? diag::warn_attribute_dllimport_static_field_definition
14326 : diag::err_attribute_dllimport_static_field_definition);
14327 Diag(IA->getLocation(), diag::note_attribute);
14328 if (!IsClassTemplateMember)
14356 if (RetainAttr *
Attr = VD->
getAttr<RetainAttr>()) {
14368 AddPushedVisibilityAttribute(VD);
14371 if (VD->
isFileVarDecl() && !isa<VarTemplatePartialSpecializationDecl>(VD))
14372 MarkUnusedFileScopedDecl(VD);
14376 if (!VD->
hasAttr<TypeTagForDatatypeAttr>() ||
14380 for (
const auto *I : ThisDecl->
specific_attrs<TypeTagForDatatypeAttr>()) {
14382 if (!MagicValueExpr) {
14385 std::optional<llvm::APSInt> MagicValueInt;
14387 Diag(I->getRange().getBegin(),
14388 diag::err_type_tag_for_datatype_not_ice)
14392 if (MagicValueInt->getActiveBits() > 64) {
14393 Diag(I->getRange().getBegin(),
14394 diag::err_type_tag_for_datatype_too_large)
14398 uint64_t MagicValue = MagicValueInt->getZExtValue();
14399 RegisterTypeTagForDatatype(I->getArgumentKind(),
14401 I->getMatchingCType(),
14402 I->getLayoutCompatible(),
14403 I->getMustBeNull());
14408 auto *VD = dyn_cast<VarDecl>(DD);
14409 return VD && !VD->getType()->hasAutoForTrailingReturnType();
14421 bool DiagnosedMultipleDecomps =
false;
14423 bool DiagnosedNonDeducedAuto =
false;
14425 for (
unsigned i = 0, e =
Group.size(); i != e; ++i) {
14429 if (
auto *DD = dyn_cast<DeclaratorDecl>(D)) {
14430 if (!FirstDeclaratorInGroup)
14431 FirstDeclaratorInGroup = DD;
14432 if (!FirstDecompDeclaratorInGroup)
14433 FirstDecompDeclaratorInGroup = dyn_cast<DecompositionDecl>(D);
14436 FirstNonDeducedAutoInGroup = DD;
14438 if (FirstDeclaratorInGroup != DD) {
14441 if (FirstDecompDeclaratorInGroup && !DiagnosedMultipleDecomps) {
14443 diag::err_decomp_decl_not_alone)
14445 << DD->getSourceRange();
14446 DiagnosedMultipleDecomps =
true;
14452 if (FirstNonDeducedAutoInGroup && !DiagnosedNonDeducedAuto) {
14454 diag::err_auto_non_deduced_not_alone)
14455 << FirstNonDeducedAutoInGroup->
getType()
14458 << DD->getSourceRange();
14459 DiagnosedNonDeducedAuto =
true;
14464 Decls.push_back(D);
14470 handleTagNumbering(Tag, S);
14471 if (FirstDeclaratorInGroup && !Tag->hasNameForLinkage() &&
14477 return BuildDeclaratorGroup(Decls);
14487 if (
Group.size() > 1) {
14489 VarDecl *DeducedDecl =
nullptr;
14490 for (
unsigned i = 0, e =
Group.size(); i != e; ++i) {
14501 auto *AT = dyn_cast<AutoType>(DT);
14503 diag::err_auto_different_deductions)
14504 << (AT ? (
unsigned)AT->getKeyword() : 3) << Deduced
14517 ActOnDocumentableDecls(
Group);
14519 return DeclGroupPtrTy::make(
14524 ActOnDocumentableDecls(D);
14532 if (Diags.isIgnored(diag::warn_doc_param_not_found,
14533 Group[0]->getLocation()) &&
14534 Diags.isIgnored(diag::warn_unknown_comment_command_name,
14535 Group[0]->getLocation()))
14538 if (
Group.size() >= 2) {
14547 if (MaybeTagDecl && isa<TagDecl>(MaybeTagDecl)) {
14564 CheckExtraCXXDefaultArguments(D);
14586 << GetNameForDeclarator(D).getName();
14612 getLangOpts().
CPlusPlus17 ? diag::ext_register_storage_class
14613 : diag::warn_deprecated_register)
14621 diag::err_invalid_storage_class_in_func_decl);
14630 << getLangOpts().CPlusPlus17;
14635 DiagnoseFunctionSpecifiers(DS);
14637 CheckFunctionOrTemplateParamDeclarator(S, D);
14646 ForVisibleRedeclaration);
14654 PrevDecl =
nullptr;
14655 }
else if (S->isDeclScope(PrevDecl)) {
14677 assert(S->isFunctionPrototypeScope());
14678 assert(S->getFunctionPrototypeDepth() >= 1);
14680 S->getNextFunctionPrototypeIndex());
14685 IdResolver.AddDecl(New);
14687 ProcessDeclAttributes(S, New, D);
14694 if (New->
hasAttr<BlocksAttr>()) {
14698 if (getLangOpts().
OpenCL)
14699 deduceOpenCLAddressSpace(New);
14722 if (inTemplateInstantiation())
14728 Diag(
Parameter->getLocation(), diag::warn_unused_parameter)
14736 if (LangOpts.NumLargeByValueCopy == 0)
14743 if (Size > LangOpts.NumLargeByValueCopy)
14754 if (Size > LangOpts.NumLargeByValueCopy)
14765 if (getLangOpts().ObjCAutoRefCount &&
14779 NameLoc, diag::err_arc_array_param_no_ownership, T,
false));
14781 Diag(NameLoc, diag::err_arc_array_param_no_ownership)
14793 TSInfo, SC,
nullptr);
14799 if (
auto *LSI = getEnclosingLambda())
14800 LSI->LocalPacks.push_back(New);
14805 NTCUC_FunctionParam, NTCUK_Destruct|NTCUK_Copy);
14810 if (!CurContext->isRecord() &&
14811 RequireNonAbstractType(NameLoc, T, diag::err_abstract_type_in_decl,
14812 AbstractParamType))
14821 diag::err_object_cannot_be_passed_returned_by_value) << 1 << T
14834 !(getLangOpts().
OpenCL &&
14836 Diag(NameLoc, diag::err_arg_with_address_space);
14864 for (
int i = FTI.
NumParams; i != 0; ) {
14867 if (getLangOpts().
C99) {
14869 llvm::raw_svector_ostream(Code)
14880 const char* PrevSpec;
14890 FTI.
Params[i].
Param = ActOnParamDeclarator(S, ParamD);
14900 assert(getCurFunctionDecl() ==
nullptr &&
"Function parsing confused");
14912 if (LangOpts.OpenMP && isInOpenMPDeclareVariantScope())
14913 ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
14914 ParentScope, D, TemplateParameterLists, Bases);
14917 Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists);
14918 Decl *Dcl = ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody, BodyKind);
14920 if (!Bases.empty())
14921 ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(Dcl, Bases);
14927 Consumer.HandleInlineFunctionDefinition(D);
14936 if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
14939 PossiblePrototype = Prev;
14957 if (isa<CXXMethodDecl>(FD))
14963 if (II->isStr(
"main") || II->isStr(
"efi_main"))
14979 if (FD->
hasAttr<OpenCLKernelAttr>())
15008 if (
FunctionDecl *OrigDef = Definition->getInstantiatedFromMemberFunction()) {
15025 if (TypoCorrectedFunctionDefinitions.count(Definition))
15030 if (SkipBody && !hasVisibleDefinition(Definition) &&
15032 Definition->isInlined() ||
15033 Definition->getDescribedFunctionTemplate() ||
15034 Definition->getNumTemplateParameterLists())) {
15037 if (
auto *TD = Definition->getDescribedFunctionTemplate())
15038 makeMergedDefinitionVisible(TD);
15039 makeMergedDefinitionVisible(
const_cast<FunctionDecl*
>(Definition));
15043 if (getLangOpts().
GNUMode && Definition->isInlineSpecified() &&
15044 Definition->getStorageClass() ==
SC_Extern)
15046 << FD << getLangOpts().CPlusPlus;
15050 Diag(Definition->getLocation(), diag::note_previous_definition);
15060 LSI->
Lambda = LambdaClass;
15078 for (
const auto &C : LambdaClass->
captures()) {
15079 if (C.capturesVariable()) {
15083 const bool ByRef = C.getCaptureKind() ==
LCK_ByRef;
15085 true, C.getLocation(),
15086 C.isPackExpansion()
15088 I->getType(),
false);
15090 }
else if (C.capturesThis()) {
15107 PushFunctionScope();
15108 PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
15115 FD = FunTmpl->getTemplatedDecl();
15117 FD = cast<FunctionDecl>(D);
15126 PushExpressionEvaluationContext(
15127 FD->
isConsteval() ? ExpressionEvaluationContext::ImmediateFunctionContext
15128 : ExprEvalContexts.back().Context);
15131 if (
const auto *
Attr = FD->
getAttr<AliasAttr>()) {
15136 if (
const auto *
Attr = FD->
getAttr<IFuncAttr>()) {
15141 if (
const auto *
Attr = FD->
getAttr<TargetVersionAttr>()) {
15143 !
Attr->isDefaultVersion()) {
15152 if (
auto *Ctor = dyn_cast<CXXConstructorDecl>(FD)) {
15154 Ctor->isDefaultConstructor() &&
15158 InstantiateDefaultCtorDefaultArgs(Ctor);
15166 CheckForFunctionRedefinition(FD,
nullptr, SkipBody);
15188 assert(inTemplateInstantiation() &&
15189 "There should be an active template instantiation on the stack "
15190 "when instantiating a generic lambda!");
15194 PushFunctionScope();
15211 RequireCompleteType(FD->
getLocation(), ResultType,
15212 diag::err_func_def_incomplete_result))
15216 PushDeclContext(FnBodyScope, FD);
15227 auto *NonParmDecl = dyn_cast<NamedDecl>(NPD);
15230 assert(!isa<ParmVarDecl>(NonParmDecl) &&
15231 "parameters should not be in newly created FD yet");
15234 if (NonParmDecl->getDeclName())
15235 PushOnScopeChains(NonParmDecl, FnBodyScope,
false);
15239 if (
auto *ED = dyn_cast<EnumDecl>(NonParmDecl)) {
15240 for (
auto *EI : ED->enumerators())
15241 PushOnScopeChains(EI, FnBodyScope,
false);
15248 Param->setOwningFunction(FD);
15251 if (Param->getIdentifier() && FnBodyScope) {
15252 CheckShadow(FnBodyScope, Param);
15254 PushOnScopeChains(Param, FnBodyScope);
15263 if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
15280 assert(!FD->
hasAttr<DLLExportAttr>());
15281 Diag(FD->
getLocation(), diag::err_attribute_dllimport_function_definition);
15287 ActOnDocumentableDecl(D);
15288 if (getCurLexicalContext()->isObjCContainer() &&
15289 getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl &&
15290 getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation)
15311 for (
unsigned I = 0, E =
Scope->Returns.size(); I != E; ++I) {
15312 if (
const VarDecl *NRVOCandidate = Returns[I]->getNRVOCandidate()) {
15313 if (!NRVOCandidate->isNRVOVariable())
15332 Outer.Fun.hasTrailingReturnType()) {
15333 QualType Ty = GetTypeFromParser(Outer.Fun.getTrailingReturnType());
15350 if (FD->isConstexpr())
15355 if (FD->getReturnType()->getContainedDeducedType())
15358 return Consumer.shouldSkipFunctionBody(D);
15365 FD->setHasSkippedBody();
15372 return ActOnFinishFunctionBody(D, BodyArg,
false);
15387 bool IsLambda =
false;
15391 llvm::DenseMap<const BlockDecl *, bool> EscapeInfo;
15393 auto IsOrNestedInEscapingBlock = [&](
const BlockDecl *BD) {
15394 if (EscapeInfo.count(BD))
15395 return EscapeInfo[BD];
15407 return EscapeInfo[BD] = R;
15412 for (
const std::pair<SourceLocation, const BlockDecl *> &
P :
15414 if (IsOrNestedInEscapingBlock(
P.second))
15415 S.
Diag(
P.first, diag::warn_implicitly_retains_self)
15420 bool IsInstantiation) {
15425 FD->
addAttr(StrictFPAttr::CreateImplicit(Context));
15430 if (getLangOpts().Coroutines && FSI->
isCoroutine())
15431 CheckCompletedCoroutineBody(FD, Body);
15455 Expr *Dummy =
nullptr;
15456 if (DeduceFunctionTypeFromReturnExpr(
15465 auto *LSI = getCurLambda();
15466 if (LSI->HasImplicitReturnType) {
15467 deduceClosureReturnType(*LSI);
15473 LSI->ReturnType.isNull() ? Context.
VoidTy : LSI->ReturnType;
15478 Proto->getExtProtoInfo()));
15498 DiagnoseSizeOfParametersAndReturnValue(FD->
parameters(),
15503 MarkVTableUsed(FD->
getLocation(), Constructor->getParent());
15505 dyn_cast<CXXDestructorDecl>(FD))
15506 MarkVTableUsed(FD->
getLocation(), Destructor->getParent());
15513 computeNRVO(Body, FSI);
15525 if (PossiblePrototype) {
15529 TypeLoc TL = TI->getTypeLoc();
15532 diag::note_declaration_not_a_prototype)
15535 FTL.getRParenLoc(),
"void")
15542 std::pair<FileID, unsigned> LocInfo =
SM.getDecomposedLoc(Loc);
15543 if (LocInfo.first.isInvalid())
15546 bool Invalid =
false;
15547 StringRef Buffer =
SM.getBufferData(LocInfo.first, &Invalid);
15551 if (LocInfo.second > Buffer.size())
15554 const char *LexStart = Buffer.data() + LocInfo.second;
15555 StringRef StartTok(LexStart, Buffer.size() - LocInfo.second);
15557 return StartTok.consume_front(
"const") &&
15559 StartTok.startswith(
"/*") || StartTok.startswith(
"//"));
15562 auto findBeginLoc = [&]() {
15570 if (isLocAtConst(FD->
getBeginLoc(), getSourceManager(),
15578 diag::note_static_for_internal_linkage)
15589 if (!PossiblePrototype)
15635 if (PossiblePrototype)
15637 diag::warn_non_prototype_changes_behavior)
15644 if (
const auto *CmpndBody = dyn_cast<CompoundStmt>(Body))
15645 if (!CmpndBody->body_empty())
15646 Diag(CmpndBody->body_front()->getBeginLoc(),
15647 diag::warn_dispatch_body_ignored);
15649 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
15664 if (KeyFunction && KeyFunction->
isDefined(Definition))
15665 MarkVTableUsed(Definition->getLocation(), MD->
getParent(),
true);
15674 (FD == getCurFunctionDecl() || getCurLambda()->CallOperator == FD) &&
15675 "Function parsing confused");
15676 }
else if (
ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
15677 assert(MD == getCurMethodDecl() &&
"Method parsing confused");
15680 DiagnoseSizeOfParametersAndReturnValue(MD->
parameters(),
15684 computeNRVO(Body, FSI);
15688 << MD->getSelector().getAsString();
15693 bool isDesignated =
15694 MD->isDesignatedInitializerForTheInterface(&InitMethod);
15695 assert(isDesignated && InitMethod);
15696 (void)isDesignated;
15699 auto IFace = MD->getClassInterface();
15702 auto SuperD = IFace->getSuperClass();
15712 diag::warn_objc_designated_init_missing_super_call);
15714 diag::note_objc_designated_init_marked_here);
15722 diag::warn_objc_secondary_init_missing_init_call);
15730 PopFunctionScopeInfo(ActivePolicy, dcl);
15735 DiagnoseUnguardedAvailabilityViolations(dcl);
15738 "This should only be set for ObjC methods, which should have been "
15739 "handled in the block above.");
15746 if (FD && isa<CXXConstructorDecl>(FD) && isa<CXXTryStmt>(Body))
15747 DiagnoseReturnInConstructorExceptionHandler(cast<CXXTryStmt>(Body));
15751 DiagnoseInvalidJumps(Body);
15754 if (!Destructor->getParent()->isDependentType())
15755 CheckDestructor(Destructor);
15757 MarkBaseAndMemberDestructorsReferenced(Destructor->getLocation(),
15758 Destructor->getParent());
15764 if (hasUncompilableErrorOccurred() ||
15765 getDiagnostics().getSuppressAllDiagnostics()) {
15766 DiscardCleanupsInEvaluationContext();
15768 if (!hasUncompilableErrorOccurred() && !isa<FunctionTemplateDecl>(dcl)) {
15771 ActivePolicy = &WP;
15775 !CheckConstexprFunctionDefinition(FD, CheckConstexprKind::Diagnose))
15778 if (FD && FD->
hasAttr<NakedAttr>()) {
15782 bool RegisterVariables =
false;
15783 if (
auto *DS = dyn_cast<DeclStmt>(S)) {
15784 for (
const auto *
Decl : DS->decls()) {
15785 if (
const auto *Var = dyn_cast<VarDecl>(
Decl)) {
15786 RegisterVariables =
15787 Var->hasAttr<AsmLabelAttr>() && !Var->hasInit();
15788 if (!RegisterVariables)
15793 if (RegisterVariables)
15795 if (!isa<AsmStmt>(S) && !isa<NullStmt>(S)) {
15796 Diag(S->getBeginLoc(), diag::err_non_asm_stmt_in_naked_function);
15797 Diag(FD->
getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
15804 assert(ExprCleanupObjects.size() ==
15805 ExprEvalContexts.back().NumCleanupObjects &&
15806 "Leftover temporaries in function");
15807 assert(!Cleanup.exprNeedsCleanups() &&
15808 "Unaccounted cleanups in function");
15809 assert(MaybeODRUseExprs.empty() &&
15810 "Leftover expressions for odr-use checking");
15816 if (!IsInstantiation)
15819 PopFunctionScopeInfo(ActivePolicy, dcl);
15823 if (hasUncompilableErrorOccurred()) {
15824 DiscardCleanupsInEvaluationContext();
15827 if (FD && ((LangOpts.OpenMP && (LangOpts.OpenMPIsDevice ||
15829 LangOpts.CUDA || LangOpts.SYCLIsDevice)) {
15830 auto ES = getEmissionStatus(FD);
15833 DeclsToCheckForDeferredDiags.insert(FD);
15848 D = TD->getTemplatedDecl();
15849 ProcessDeclAttributeList(S, D, Attrs);
15851 if (
CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(D))
15852 if (Method->isStatic())
15853 checkThisInStaticMemberFunctionAttributes(Method);
15862 "Implicit function declarations aren't allowed in this language mode");
15869 Scope *BlockScope = S;
15873 Scope *ContextScope = BlockScope;
15875 ContextScope = ContextScope->
getParent();
15882 NamedDecl *ExternCPrev = findLocallyScopedExternCDecl(&II);
15886 PushOnScopeChains(ExternCPrev, BlockScope,
false);
15891 if (!isa<FunctionDecl>(ExternCPrev) ||
15893 cast<FunctionDecl>(ExternCPrev)->getType(),
15895 Diag(Loc, diag::ext_use_out_of_scope_declaration)
15896 << ExternCPrev << !getLangOpts().C99;
15898 return ExternCPrev;
15904 if (II.
getName().startswith(
"__builtin_"))
15905 diag_id = diag::warn_builtin_unknown;
15907 else if (getLangOpts().
C99)
15908 diag_id = diag::ext_implicit_function_decl_c99;
15910 diag_id = diag::warn_implicit_function_decl;
15918 if (S && !ExternCPrev &&
15922 S,
nullptr, CCC, CTK_NonError);
15925 Diag(Loc, diag_id) << &II;
15929 bool Diagnose =
true;
15933 diagnoseTypo(Corrected, PDiag(diag::note_function_suggestion),
15941 return ExternCPrev;
15951 assert(!
Error &&
"Error setting up implicit decl!");
15976 FunctionDecl *FD = cast<FunctionDecl>(ActOnDeclarator(BlockScope, D));
15979 AddKnownFunctionAttributes(FD);
15999 std::optional<unsigned> AlignmentParam;
16000 bool IsNothrow =
false;
16009 if (!IsNothrow && !FD->
hasAttr<ReturnsNonNullAttr>())
16026 if (!FD->
hasAttr<AllocSizeAttr>()) {
16027 FD->
addAttr(AllocSizeAttr::CreateImplicit(
16038 if (AlignmentParam && !FD->
hasAttr<AllocAlignAttr>()) {
16039 FD->
addAttr(AllocAlignAttr::CreateImplicit(
16072 unsigned FormatIdx;
16075 if (!FD->
hasAttr<FormatAttr>()) {
16076 const char *fmt =
"printf";
16078 if (FormatIdx < NumParams &&
16081 FD->
addAttr(FormatAttr::CreateImplicit(Context,
16084 HasVAListArg ? 0 : FormatIdx+2,
16090 if (!FD->
hasAttr<FormatAttr>())
16091 FD->
addAttr(FormatAttr::CreateImplicit(Context,
16094 HasVAListArg ? 0 : FormatIdx+2,
16100 if (!FD->
hasAttr<CallbackAttr>() &&
16102 FD->
addAttr(CallbackAttr::CreateImplicit(
16108 bool NoExceptions =
16110 bool ConstWithoutErrnoAndExceptions =
16112 bool ConstWithoutExceptions =
16114 if (!FD->
hasAttr<ConstAttr>() &&
16115 (ConstWithoutErrnoAndExceptions || ConstWithoutExceptions) &&
16116 (!ConstWithoutErrnoAndExceptions ||
16117 (!getLangOpts().MathErrno && NoExceptions)) &&
16118 (!ConstWithoutExceptions || NoExceptions))
16125 if ((Trip.isGNUEnvironment() || Trip.isOSMSVCRT()) &&
16127 switch (BuiltinID) {
16128 case Builtin::BI__builtin_fma:
16129 case Builtin::BI__builtin_fmaf:
16130 case Builtin::BI__builtin_fmal:
16131 case Builtin::BIfma:
16132 case Builtin::BIfmaf:
16133 case Builtin::BIfmal:
16142 !FD->
hasAttr<ReturnsTwiceAttr>())
16143 FD->
addAttr(ReturnsTwiceAttr::CreateImplicit(Context,
16152 !FD->
hasAttr<CUDADeviceAttr>() && !FD->
hasAttr<CUDAHostAttr>()) {
16156 if (getLangOpts().CUDAIsDevice !=
16164 switch (BuiltinID) {
16165 case Builtin::BImemalign:
16166 case Builtin::BIaligned_alloc:
16167 if (!FD->
hasAttr<AllocAlignAttr>())
16176 switch (BuiltinID) {
16177 case Builtin::BIcalloc:
16178 FD->
addAttr(AllocSizeAttr::CreateImplicit(
16181 case Builtin::BImemalign:
16182 case Builtin::BIaligned_alloc:
16183 case Builtin::BIrealloc:
16187 case Builtin::BImalloc:
16196 switch (BuiltinID) {
16197 case Builtin::BIaddressof:
16198 case Builtin::BI__addressof:
16199 case Builtin::BI__builtin_addressof:
16200 case Builtin::BIas_const:
16201 case Builtin::BIforward:
16202 case Builtin::BIforward_like:
16203 case Builtin::BImove:
16204 case Builtin::BImove_if_noexcept:
16206 !
P->hasAttr<LifetimeBoundAttr>())
16208 LifetimeBoundAttr::CreateImplicit(Context, FD->
getLocation()));
16215 AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction(FD);
16220 if (getLangOpts().CXXExceptions && getLangOpts().ExternCNoUnwind &&
16223 if (!FPT || FPT->getExceptionSpecType() ==
EST_None)
16240 if (Name->isStr(
"asprintf") || Name->isStr(
"vasprintf")) {
16243 if (!FD->
hasAttr<FormatAttr>())
16244 FD->
addAttr(FormatAttr::CreateImplicit(Context,
16246 Name->isStr(
"vasprintf") ? 0 : 3,
16250 if (Name->isStr(
"__CFStringMakeConstantString")) {
16253 if (!FD->
hasAttr<FormatArgAttr>())
16261 assert(D.
getIdentifier() &&
"Wrong callback for declspec without declarator");
16262 assert(!T.
isNull() &&
"GetTypeForDeclarator() returned null type");
16265 assert(D.
isInvalidType() &&
"no declarator info for valid type");
16281 if (CurContext->isFunctionOrMethod())
16304 setTagNameForLinkagePurposes(tagFromDeclSpec, NewTD);
16326 if (BT->isInteger())
16332 return Diag(UnderlyingLoc, diag::err_enum_invalid_underlying) << T;
16338 QualType EnumUnderlyingTy,
bool IsFixed,
16340 if (IsScoped != Prev->
isScoped()) {
16341 Diag(EnumLoc, diag::err_enum_redeclare_scoped_mismatch)
16347 if (IsFixed && Prev->
isFixed()) {
16353 Diag(EnumLoc, diag::err_enum_redeclare_type_mismatch)
16359 }
else if (IsFixed != Prev->
isFixed()) {
16360 Diag(EnumLoc, diag::err_enum_redeclare_fixed_mismatch)
16379 default: llvm_unreachable(
"Invalid tag kind for redecl diagnostic!");
16394 if (isa<TypedefDecl>(PrevDecl))
16395 return NTK_Typedef;
16396 else if (isa<TypeAliasDecl>(PrevDecl))
16397 return NTK_TypeAlias;
16398 else if (isa<ClassTemplateDecl>(PrevDecl))
16399 return NTK_Template;
16400 else if (isa<TypeAliasTemplateDecl>(PrevDecl))
16401 return NTK_TypeAliasTemplate;
16402 else if (isa<TemplateTemplateParmDecl>(PrevDecl))
16403 return NTK_TemplateTemplateArgument;
16408 return getLangOpts().CPlusPlus ? NTK_NonClass : NTK_NonStruct;
16410 return NTK_NonUnion;
16412 return NTK_NonEnum;
16414 llvm_unreachable(
"invalid TTK");
16439 if (OldTag != NewTag &&
16454 return getDiagnostics().isIgnored(diag::warn_struct_class_tag_mismatch,
16457 if (IsIgnoredLoc(NewTagLoc))
16460 auto IsIgnored = [&](
const TagDecl *Tag) {
16461 return IsIgnoredLoc(Tag->getLocation());
16472 isTemplate = Record->getDescribedClassTemplate();
16474 if (inTemplateInstantiation()) {
16475 if (OldTag != NewTag) {
16478 Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
16486 if (isDefinition) {
16494 bool previousMismatch =
false;
16496 if (I->getTagKind() != NewTag) {
16501 if (!previousMismatch) {
16502 previousMismatch =
true;
16503 Diag(NewTagLoc, diag::warn_struct_class_previous_tag_mismatch)
16507 Diag(I->getInnerLocStart(), diag::note_struct_class_suggestion)
16520 if (PrevDef && IsIgnored(PrevDef))
16524 Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
16531 Diag(NewTagLoc, diag::note_struct_class_suggestion)
16561 if (!Namespace || Namespace->isAnonymousNamespace())
16564 Namespaces.push_back(II);
16567 if (Lookup == Namespace)
16574 llvm::raw_svector_ostream OS(Insertion);
16577 std::reverse(Namespaces.begin(), Namespaces.end());
16578 for (
auto *II : Namespaces)
16579 OS << II->getName() <<
"::";
16592 if (OldDC->
Equals(NewDC))
16621 bool ScopedEnumUsesClassTag,
TypeResult UnderlyingType,
16622 bool IsTypeSpecifier,
bool IsTemplateParamOrArg,
16626 assert((Name !=
nullptr || TUK == TUK_Definition) &&
16627 "Nameless record must be a definition!");
16628 assert(TemplateParameterLists.size() == 0 || TUK != TUK_Reference);
16632 bool ScopedEnum = ScopedEnumKWLoc.
isValid();
16635 bool isMemberSpecialization =
false;
16636 bool Invalid =
false;
16641 if (TemplateParameterLists.size() > 0 ||
16642 (SS.
isNotEmpty() && TUK != TUK_Reference)) {
16644 MatchTemplateParametersToScopeSpecifier(
16645 KWLoc, NameLoc, SS,
nullptr, TemplateParameterLists,
16646 TUK == TUK_Friend, isMemberSpecialization, Invalid)) {
16648 Diag(KWLoc, diag::err_enum_template);
16652 if (TemplateParams->size() > 0) {
16661 S, TagSpec, TUK, KWLoc, SS, Name, NameLoc, Attrs, TemplateParams,
16662 AS, ModulePrivateLoc,
16664 TemplateParameterLists.data(), SkipBody);
16665 return Result.get();
16668 Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams)
16670 isMemberSpecialization =
true;
16674 if (!TemplateParameterLists.empty() && isMemberSpecialization &&
16675 CheckTemplateDeclScope(S, TemplateParameterLists.back()))
16682 llvm::PointerUnion<const Type*, TypeSourceInfo*> EnumUnderlying;
16683 bool IsFixed = !UnderlyingType.
isUnset() || ScopedEnum;
16686 if (UnderlyingType.
isInvalid() || (!UnderlyingType.
get() && ScopedEnum)) {
16690 }
else if (UnderlyingType.
get()) {
16694 GetTypeFromParser(UnderlyingType.
get(), &TI);
16695 EnumUnderlying = TI;
16697 if (CheckEnumUnderlyingType(TI))
16702 UPPC_FixedUnderlyingType))
16710 if (TUK == TUK_Definition || getLangOpts().MSVCCompat)
16717 bool isStdBadAlloc =
false;
16718 bool isStdAlignValT =
false;
16721 if (TUK == TUK_Friend || TUK == TUK_Reference)
16722 Redecl = NotForRedeclaration;
16727 auto createTagFromNewDecl = [&]() ->
TagDecl * {
16728 assert(!getLangOpts().
CPlusPlus &&
"not meant for C++ usage");
16737 ScopedEnum, ScopedEnumUsesClassTag, IsFixed);
16739 if (TUK != TUK_Definition && !Invalid)
16741 if (EnumUnderlying) {
16742 EnumDecl *ED = cast<EnumDecl>(New);
16757 if (
RecordDecl *RD = dyn_cast<RecordDecl>(New)) {
16767 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip)) {
16768 AddAlignmentAttributesForRecord(RD);
16769 AddMsStructLayoutForRecord(RD);
16783 goto CreateNewDecl;
16788 if (TUK == TUK_Friend || TUK == TUK_Reference) {
16789 DC = computeDeclContext(SS,
false);
16791 IsDependent =
true;
16795 DC = computeDeclContext(SS,
true);
16803 if (RequireCompleteDeclContext(SS, DC))
16808 LookupQualifiedName(
Previous, DC);
16820 if (
Previous.wasNotFoundInCurrentInstantiation() &&
16821 (TUK == TUK_Reference || TUK == TUK_Friend)) {
16822 IsDependent =
true;
16827 Diag(NameLoc, diag::err_not_tag_in_scope)
16831 goto CreateNewDecl;
16838 if (TUK != TUK_Reference && TUK != TUK_Friend &&
16852 (TUK == TUK_Definition || TUK == TUK_Declaration)) {
16876 if (!
Previous.empty() && TUK == TUK_Friend) {
16879 bool FriendSawTagOutsideEnclosingNamespace =
false;
16885 if (getLangOpts().MSVCCompat)
16886 FriendSawTagOutsideEnclosingNamespace =
true;
16895 if (
Previous.isSingleResult() && FriendSawTagOutsideEnclosingNamespace) {
16897 Diag(NameLoc, diag::ext_friend_tag_redecl_outside_namespace)
16906 if (!getLangOpts().
CPlusPlus && TUK != TUK_Reference) {
16911 while (isa<RecordDecl, EnumDecl, ObjCContainerDecl>(SearchDC))
16917 while (isa<ObjCContainerDecl>(SearchDC))
16923 while (isa<ObjCContainerDecl>(SearchDC))
16928 Previous.getFoundDecl()->isTemplateParameter()) {
16930 DiagnoseTemplateParameterShadow(NameLoc,
Previous.getFoundDecl());
16935 if (getLangOpts().
CPlusPlus && Name && DC && StdNamespace &&
16936 DC->
Equals(getStdNamespace())) {
16937 if (Name->isStr(
"bad_alloc")) {
16939 isStdBadAlloc =
true;
16944 if (
Previous.empty() && StdBadAlloc)
16945 Previous.addDecl(getStdBadAlloc());
16946 }
else if (Name->isStr(
"align_val_t")) {
16947 isStdAlignValT =
true;
16948 if (
Previous.empty() && StdAlignValT)
16949 Previous.addDecl(getStdAlignValT());
16958 (TUK == TUK_Reference || TUK == TUK_Friend || IsTemplateParamOrArg)) {
16959 if (Invalid)
goto CreateNewDecl;
16962 if (TUK == TUK_Reference || IsTemplateParamOrArg) {
16996 assert(TUK == TUK_Friend);
17013 Previous.setRedeclarationKind(forRedeclarationInCurContext());
17014 LookupQualifiedName(
Previous, SearchDC);
17016 Previous.setRedeclarationKind(forRedeclarationInCurContext());
17040 TagDecl *Tag = TT->getDecl();
17043 ->
Equals(TD->getDeclContext()->getRedeclContext())) {
17056 if (
auto *Shadow = dyn_cast<UsingShadowDecl>(DirectPrevDecl)) {
17057 auto *OldTag = dyn_cast<TagDecl>(PrevDecl);
17058 if (SS.
isEmpty() && TUK != TUK_Reference && TUK != TUK_Friend &&
17059 isDeclInScope(Shadow, SearchDC, S, isMemberSpecialization) &&
17061 *
this, OldTag->getDeclContext(), SearchDC))) {
17062 Diag(KWLoc, diag::err_using_decl_conflict_reverse);
17063 Diag(Shadow->getTargetDecl()->getLocation(),
17064 diag::note_using_decl_target);
17065 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
17069 goto CreateNewDecl;
17073 if (
TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) {
17077 if (TUK == TUK_Reference || TUK == TUK_Friend ||
17078 isDeclInScope(DirectPrevDecl, SearchDC, S,
17079 SS.
isNotEmpty() || isMemberSpecialization)) {
17082 if (!isAcceptableTagRedeclaration(PrevTagDecl,
Kind,
17083 TUK == TUK_Definition, KWLoc,
17085 bool SafeToContinue
17086 = (PrevTagDecl->getTagKind() !=
TTK_Enum &&
17088 if (SafeToContinue)
17089 Diag(KWLoc, diag::err_use_with_wrong_tag)
17092 PrevTagDecl->getKindName());
17094 Diag(KWLoc, diag::err_use_with_wrong_tag) << Name;
17095 Diag(PrevTagDecl->getLocation(), diag::note_previous_use);
17097 if (SafeToContinue)
17098 Kind = PrevTagDecl->getTagKind();
17108 const EnumDecl *PrevEnum = cast<EnumDecl>(PrevTagDecl);
17109 if (TUK == TUK_Reference || TUK == TUK_Friend)
17110 return PrevTagDecl;
17114 EnumUnderlyingTy = TI->getType().getUnqualifiedType();
17115 else if (
const Type *T = EnumUnderlying.dyn_cast<
const Type*>())
17116 EnumUnderlyingTy =
QualType(T, 0);
17121 if (CheckEnumRedeclaration(NameLoc.
isValid() ? NameLoc : KWLoc,
17122 ScopedEnum, EnumUnderlyingTy,
17123 IsFixed, PrevEnum))
17124 return TUK == TUK_Declaration ? PrevTagDecl :
nullptr;
17132 S->isDeclScope(PrevDecl)) {
17133 Diag(NameLoc, diag::ext_member_redeclared);
17134 Diag(PrevTagDecl->getLocation(), diag::note_previous_declaration);
17140 if (TUK == TUK_Reference || TUK == TUK_Friend) {
17141 if (!Attrs.
empty()) {
17144 }
else if (TUK == TUK_Reference &&
17145 (PrevTagDecl->getFriendObjectKind() ==
17158 return PrevTagDecl;
17163 return PrevTagDecl;
17168 if (TUK == TUK_Definition) {
17169 if (
NamedDecl *Def = PrevTagDecl->getDefinition()) {
17173 bool IsExplicitSpecializationAfterInstantiation =
false;
17174 if (isMemberSpecialization) {
17176 IsExplicitSpecializationAfterInstantiation =
17177 RD->getTemplateSpecializationKind() !=
17179 else if (
EnumDecl *ED = dyn_cast<EnumDecl>(Def))
17180 IsExplicitSpecializationAfterInstantiation =
17181 ED->getTemplateSpecializationKind() !=
17190 if (SkipBody && !hasVisibleDefinition(Def, &Hidden)) {
17201 SkipBody->
New = createTagFromNewDecl();
17207 makeMergedDefinitionVisible(Hidden);
17211 }
else if (!IsExplicitSpecializationAfterInstantiation) {
17214 if (!getLangOpts().
CPlusPlus && S->containedInPrototypeScope())
17215 Diag(NameLoc, diag::warn_redefinition_in_param_list) << Name;
17217 Diag(NameLoc, diag::err_redefinition) << Name;
17218 notePreviousDefinition(Def,
17219 NameLoc.
isValid() ? NameLoc : KWLoc);
17231 if (TD->isBeingDefined()) {
17232 Diag(NameLoc, diag::err_nested_redefinition) << Name;
17233 Diag(PrevTagDecl->getLocation(),
17234 diag::note_previous_definition);
17248 if (TUK == TUK_Friend || TUK == TUK_Reference) {
17249 SearchDC = PrevTagDecl->getDeclContext();
17274 if ((TUK == TUK_Reference || TUK == TUK_Friend) &&
17277 Diag(NameLoc, diag::err_tag_reference_non_tag) << PrevDecl << NTK
17283 }
else if (!isDeclInScope(DirectPrevDecl, SearchDC, S,
17284 SS.
isNotEmpty() || isMemberSpecialization)) {
17288 }
else if (TUK == TUK_Reference || TUK == TUK_Friend) {
17290 Diag(NameLoc, diag::err_tag_reference_conflict) << NTK;
17296 }
else if (
TypedefNameDecl *TND = dyn_cast<TypedefNameDecl>(PrevDecl)) {
17298 if (isa<TypeAliasDecl>(PrevDecl))
Kind = 1;
17299 Diag(NameLoc, diag::err_tag_definition_of_typedef)
17300 << Name <<
Kind << TND->getUnderlyingType();
17308 Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
17309 notePreviousDefinition(PrevDecl, NameLoc);
17324 PrevDecl = cast<TagDecl>(
Previous.getFoundDecl());
17340 cast_or_null<EnumDecl>(PrevDecl), ScopedEnum,
17341 ScopedEnumUsesClassTag, IsFixed);
17343 if (isStdAlignValT && (!StdAlignValT || getStdAlignValT()->isImplicit()))
17344 StdAlignValT = cast<EnumDecl>(New);
17347 if (TUK != TUK_Definition && !Invalid) {
17349 if (IsFixed && cast<EnumDecl>(New)->isFixed()) {
17353 else if (PrevDecl && (Def = cast<EnumDecl>(PrevDecl)->
getDefinition())) {
17354 Diag(Loc, diag::ext_forward_ref_enum_def)
17358 unsigned DiagID = diag::ext_forward_ref_enum;
17359 if (getLangOpts().MSVCCompat)
17360 DiagID = diag::ext_ms_forward_ref_enum;
17362 DiagID = diag::err_forward_ref_enum;
17367 if (EnumUnderlying) {
17368 EnumDecl *ED = cast<EnumDecl>(New);
17377 assert(ED->
isComplete() &&
"enum with type should be complete");
17387 cast_or_null<CXXRecordDecl>(PrevDecl));
17389 if (isStdBadAlloc && (!StdBadAlloc || getStdBadAlloc()->isImplicit()))
17390 StdBadAlloc = cast<CXXRecordDecl>(New);
17393 cast_or_null<RecordDecl>(PrevDecl));
17396 if (OOK != OOK_Outside && TUK == TUK_Definition && !getLangOpts().
CPlusPlus)
17402 if (!Invalid && getLangOpts().CPlusPlus &&
17403 (IsTypeSpecifier || IsTemplateParamOrArg) && TUK == TUK_Definition) {
17409 if (!Invalid && getLangOpts().
CPlusPlus && TUK == TUK_Definition &&
17421 if ((TUK == TUK_Definition || TUK == TUK_Declaration) &&
17422 diagnoseQualifiedDeclaration(SS, DC, OrigName, Loc,
17423 isMemberSpecialization))
17427 if (TemplateParameterLists.size() > 0) {
17435 if (
RecordDecl *RD = dyn_cast<RecordDecl>(New)) {
17445 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip)) {
17446 AddAlignmentAttributesForRecord(RD);
17447 AddMsStructLayoutForRecord(RD);
17451 if (ModulePrivateLoc.
isValid()) {
17452 if (isMemberSpecialization)
17465 if (isMemberSpecialization && CheckMemberSpecialization(New,
Previous))
17472 getNonFieldDeclScope(S)->isFunctionPrototypeScope()) {
17476 if (TUK == TUK_Definition && !IsTypeSpecifier) {
17477 Diag(Loc, diag::err_type_defined_in_param_type)
17481 }
else if (!PrevDecl) {
17497 if (TUK == TUK_Friend)
17501 if (!Invalid && SearchDC->
isRecord())
17502 SetMemberAccessSpecifier(New, PrevDecl, AS);
17505 CheckRedeclarationInModule(New, PrevDecl);
17507 if (TUK == TUK_Definition && (!SkipBody || !SkipBody->
ShouldSkip))
17510 ProcessDeclAttributeList(S, New, Attrs);
17511 AddPragmaAttributes(S, New);
17514 if (TUK == TUK_Friend) {
17523 if (
Scope *EnclosingScope = getScopeForDeclContext(S, DC))
17524 PushOnScopeChains(New, EnclosingScope,
false);
17526 S = getNonFieldDeclScope(S);
17527 PushOnScopeChains(New, S,
true);
17529 CurContext->addDecl(New);
17540 mergeDeclAttributes(New, PrevDecl);
17542 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(New))
17543 inferGslOwnerPointerAttribute(CXXRD);
17547 AddPushedVisibilityAttribute(New);
17550 CompleteMemberSpecialization(New,
Previous);
17555 if (Invalid && getLangOpts().
CPlusPlus) {
17557 if (
auto RD = dyn_cast<RecordDecl>(New))
17560 }
else if (SkipBody && SkipBody->
ShouldSkip) {
17568 AdjustDeclIfTemplate(TagD);
17569 TagDecl *Tag = cast<TagDecl>(TagD);
17572 PushDeclContext(S, Tag);
17574 ActOnDocumentableDecl(TagD);
17578 AddPushedVisibilityAttribute(Tag);
17582 if (!hasStructuralCompatLayout(Prev, SkipBody.
New))
17586 makeMergedDefinitionVisible(SkipBody.
Previous);
17592 "The next DeclContext should be lexically contained in the current one.");
17593 CurContext = IDecl;
17598 bool IsFinalSpelledSealed,
17601 AdjustDeclIfTemplate(TagD);
17604 FieldCollector->StartClass();
17613 Record->
addAttr(FinalAttr::Create(
17615 static_cast<FinalAttr::Spelling
>(IsFinalSpelledSealed)));
17632 PushOnScopeChains(InjectedClassName, S);
17634 "Broken injected-class-name");
17639 AdjustDeclIfTemplate(TagD);
17640 TagDecl *Tag = cast<TagDecl>(TagD);
17645 assert(Tag->
isInvalidDecl() &&
"We should already have completed it");
17646 if (
RecordDecl *RD = dyn_cast<RecordDecl>(Tag))
17650 if (
auto *RD = dyn_cast<CXXRecordDecl>(Tag)) {
17651 FieldCollector->FinishClass();
17652 if (RD->
hasAttr<SYCLSpecialClassAttr>()) {
17654 assert(Def &&
"The record is expected to have a completed definition");
17655 unsigned NumInitMethods = 0;
17656 for (
auto *Method : Def->methods()) {
17657 if (!Method->getIdentifier())
17659 if (Method->getName() ==
"__init")
17662 if (NumInitMethods > 1 || !Def->hasInitMethod())
17663 Diag(RD->
getLocation(), diag::err_sycl_special_type_num_init_method);
17670 if (getCurLexicalContext()->isObjCContainer() &&
17676 Consumer.HandleTagDeclDefinition(Tag);
17681 AlignPackStack.hasValue()) {
17686 const RecordDecl *RD = dyn_cast<RecordDecl>(Tag);
17690 if (llvm::any_of(RD->
fields(),
17691 [](
const FieldDecl *FD) { return FD->isBitField(); }))
17692 Diag(BraceRange.
getBegin(), diag::warn_pragma_align_not_xl_compatible);
17702 assert(ObjCCtx == CurContext &&
"Mismatch of container contexts");
17703 OriginalLexicalContext = ObjCCtx;
17704 ActOnObjCContainerFinishDefinition();
17708 ActOnObjCContainerStartDefinition(ObjCCtx);
17709 OriginalLexicalContext =
nullptr;
17713 AdjustDeclIfTemplate(TagD);
17714 TagDecl *Tag = cast<TagDecl>(TagD);
17719 if (
RecordDecl *RD = dyn_cast<RecordDecl>(Tag))
17733 bool IsMsStruct,
Expr *BitWidth) {
17742 if (RequireCompleteSizedType(FieldLoc, FieldTy,
17743 diag::err_field_incomplete_or_sizeless))
17746 return Diag(FieldLoc, diag::err_not_integral_type_bitfield)
17748 return Diag(FieldLoc, diag::err_not_integral_type_anon_bitfield)
17750 }
else if (DiagnoseUnexpandedParameterPack(
const_cast<Expr *
>(BitWidth),
17751 UPPC_BitFieldWidth))
17760 ExprResult ICE = VerifyIntegerConstantExpression(BitWidth, &
Value, AllowFold);
17763 BitWidth = ICE.
get();
17766 if (
Value == 0 && FieldName)
17767 return Diag(FieldLoc, diag::err_bitfield_has_zero_width) << FieldName;
17769 if (
Value.isSigned() &&
Value.isNegative()) {
17771 return Diag(FieldLoc, diag::err_bitfield_has_negative_width)
17773 return Diag(FieldLoc, diag::err_anon_bitfield_has_negative_width)
17780 return Diag(FieldLoc, diag::err_bitfield_too_wide)
17787 bool BitfieldIsOverwide =
Value.ugt(TypeWidth);
17791 bool CStdConstraintViolation =
17792 BitfieldIsOverwide && !getLangOpts().CPlusPlus;
17793 bool MSBitfieldViolation =
17794 Value.ugt(TypeStorageSize) &&
17796 if (CStdConstraintViolation || MSBitfieldViolation) {
17797 unsigned DiagWidth =
17798 CStdConstraintViolation ? TypeWidth : TypeStorageSize;
17799 return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
17801 << !CStdConstraintViolation << DiagWidth;
17807 if (BitfieldIsOverwide && !FieldTy->
isBooleanType() && FieldName) {
17808 Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)
17821 FieldDecl *Res = HandleField(S, cast_or_null<RecordDecl>(TagD),
17822 DeclStart, D,
static_cast<Expr*
>(BitfieldWidth),
17848 CheckExtraCXXDefaultArguments(D);
17851 UPPC_DataMemberType)) {
17862 << getLangOpts().CPlusPlus17;
17865 diag::err_invalid_thread)
17871 ForVisibleRedeclaration);
17873 switch (
Previous.getResultKind()) {
17880 PrevDecl =
Previous.getRepresentativeDecl();
17894 PrevDecl =
nullptr;
17897 if (PrevDecl && !isDeclInScope(PrevDecl, Record, S))
17898 PrevDecl =
nullptr;
17904 = CheckFieldDecl(II, T, TInfo, Record, Loc, Mutable, BitWidth, InitStyle,
17905 TSSL, AS, PrevDecl, &D);
17917 PushOnScopeChains(NewFD, S);
17937 bool Mutable,
Expr *BitWidth,
17943 bool InvalidDecl =
false;
17949 InvalidDecl =
true;
17955 if (RequireCompleteSizedType(Loc, EltTy,
17956 diag::err_field_incomplete_or_sizeless)) {
17959 InvalidDecl =
true;
17965 InvalidDecl =
true;
17973 Diag(Loc, diag::err_field_with_address_space);
17975 InvalidDecl =
true;
17978 if (LangOpts.OpenCL) {
17983 Diag(Loc, diag::err_opencl_type_struct_or_union_field) << T;
17985 InvalidDecl =
true;
17989 if (BitWidth && !getOpenCLOptions().isAvailableOption(
17990 "__cl_clang_bitfields", LangOpts)) {
17991 Diag(Loc, diag::err_opencl_bitfields);
17992 InvalidDecl =
true;
17997 if (!InvalidDecl && getLangOpts().
CPlusPlus && !II && BitWidth &&
17999 InvalidDecl =
true;
18000 Diag(Loc, diag::err_anon_bitfield_qualifiers);
18006 if (!tryToFixVariablyModifiedVarType(
18007 TInfo, T, Loc, diag::err_typecheck_field_variable_size))
18008 InvalidDecl =
true;
18012 if (!InvalidDecl && RequireNonAbstractType(Loc, T,
18013 diag::err_abstract_type_in_decl,
18014 AbstractFieldType))
18015 InvalidDecl =
true;
18018 BitWidth =
nullptr;
18022 VerifyBitField(Loc, II, T, Record->
isMsStruct(Context), BitWidth).get();
18024 InvalidDecl =
true;
18025 BitWidth =
nullptr;
18030 if (!InvalidDecl && Mutable) {
18031 unsigned DiagID = 0;
18033 DiagID = getLangOpts().MSVCCompat ? diag::ext_mutable_reference
18034 : diag::err_mutable_reference;
18036 DiagID = diag::err_mutable_const;
18042 Diag(ErrLoc, DiagID);
18043 if (DiagID != diag::ext_mutable_reference) {
18045 InvalidDecl =
true;
18057 BitWidth, Mutable, InitStyle);
18061 if (PrevDecl && !isa<TagDecl>(PrevDecl)) {
18062 Diag(Loc, diag::err_duplicate_member) << II;
18067 if (!InvalidDecl && getLangOpts().
CPlusPlus) {
18077 if (CheckNontrivialField(NewFD))
18087 diag::ext_union_member_of_reference_type :
18088 diag::err_union_member_of_reference_type)
18090 if (!getLangOpts().MicrosoftExt)
18100 ProcessDeclAttributes(getCurScope(), NewFD, *D);
18103 CheckAlignasUnderalignment(NewFD);
18108 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewFD))
18112 Diag(Loc, diag::warn_attribute_weak_on_field);
18125 assert(getLangOpts().
CPlusPlus &&
"valid check only for C++");
18145 member = CXXCopyConstructor;
18147 member = CXXDefaultConstructor;
18149 member = CXXCopyAssignment;
18153 if (
member != CXXInvalid) {
18162 if (getSourceManager().isInSystemHeader(Loc)) {
18163 if (!FD->
hasAttr<UnavailableAttr>())
18164 FD->
addAttr(UnavailableAttr::CreateImplicit(Context,
"",
18165 UnavailableAttr::IR_ARCFieldWithOwnership, Loc));
18171 diag::warn_cxx98_compat_nontrivial_union_or_anon_struct_member :
18172 diag::err_illegal_union_or_anon_struct_member)
18174 DiagnoseNontrivial(RDecl,
member);
18175 return !getLangOpts().CPlusPlus11;
18187 switch (ivarVisibility) {
18188 default: llvm_unreachable(
"Unknown visitibility kind");
18204 Expr *BitWidth = (
Expr*)BitfieldWidth;
18216 BitWidth = VerifyBitField(Loc, II, T,
false, BitWidth).get();
18226 Diag(Loc, diag::err_ivar_reference_type);
18232 if (!tryToFixVariablyModifiedVarType(
18233 TInfo, T, Loc, diag::err_typecheck_ivar_variable_size))
18247 dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
18250 EnclosingContext = IMPDecl->getClassInterface();
18251 assert(EnclosingContext &&
"Implementation has no class interface!");
18254 EnclosingContext = EnclosingDecl;
18257 dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
18259 Diag(Loc, diag::err_misplaced_ivar) << CDecl->IsClassExtension();
18263 EnclosingContext = EnclosingDecl;
18268 DeclStart, Loc, II, T,
18269 TInfo, ac, (
Expr *)BitfieldWidth);
18272 NamedDecl *PrevDecl = LookupSingleName(S, II, Loc, LookupMemberName,
18273 ForVisibleRedeclaration);
18274 if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S)
18275 && !isa<TagDecl>(PrevDecl)) {
18276 Diag(Loc, diag::err_duplicate_member) << II;
18283 ProcessDeclAttributes(S, NewID, D);
18289 if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(NewID))
18299 IdResolver.AddDecl(NewID);
18303 !NewID->
isInvalidDecl() && isa<ObjCInterfaceDecl>(EnclosingDecl))
18304 Diag(Loc, diag::warn_ivars_in_interface);
18318 Decl *ivarDecl = AllIvarDecls[AllIvarDecls.size()-1];
18326 if (!CD->IsClassExtension())
18338 DeclLoc, DeclLoc,
nullptr,
18344 AllIvarDecls.push_back(Ivar);
18364 if (
auto *DD = dyn_cast<CXXDestructorDecl>(
Decl)) {
18365 if (DD->isInvalidDecl())
18369 assert(DD->isIneligibleOrNotSelected() &&
"Selecting a destructor but a destructor was already selected.");
18387 Msg = diag::err_ambiguous_destructor;
18392 Msg = diag::err_no_viable_destructor;
18451 const Expr *Constraints = Method->getTrailingRequiresClause();
18453 SatisfactionStatus.push_back(
true);
18457 SatisfactionStatus.push_back(
false);
18459 SatisfactionStatus.push_back(Satisfaction.
IsSatisfied);
18463 for (
size_t i = 0; i < Methods.size(); i++) {
18464 if (!SatisfactionStatus[i])
18469 OrigMethod = cast<CXXMethodDecl>(MF);
18472 bool AnotherMethodIsMoreConstrained =
false;
18473 for (
size_t j = 0; j < Methods.size(); j++) {
18474 if (i == j || !SatisfactionStatus[j])
18478 OtherMethod = cast<CXXMethodDecl>(MF);
18485 if (!OtherConstraints)
18487 if (!Constraints) {
18488 AnotherMethodIsMoreConstrained =
true;
18493 AnotherMethodIsMoreConstrained)) {
18496 AnotherMethodIsMoreConstrained =
true;
18498 if (AnotherMethodIsMoreConstrained)
18503 if (!AnotherMethodIsMoreConstrained) {
18519 auto *MD = dyn_cast<CXXMethodDecl>(
Decl);
18521 auto *FTD = dyn_cast<FunctionTemplateDecl>(
Decl);
18523 MD = dyn_cast<CXXMethodDecl>(FTD->getTemplatedDecl());
18527 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
18528 if (CD->isInvalidDecl())
18530 if (CD->isDefaultConstructor())
18531 DefaultConstructors.push_back(MD);
18532 else if (CD->isCopyConstructor())
18533 CopyConstructors.push_back(MD);
18534 else if (CD->isMoveConstructor())
18535 MoveConstructors.push_back(MD);
18537 CopyAssignmentOperators.push_back(MD);
18539 MoveAssignmentOperators.push_back(MD);
18557 assert(EnclosingDecl &&
"missing record or interface decl");
18562 if (!Fields.empty() && isa<ObjCContainerDecl>(EnclosingDecl)) {
18566 case Decl::ObjCCategory:
18567 Context.
ResetObjCLayout(cast<ObjCCategoryDecl>(DC)->getClassInterface());
18569 case Decl::ObjCImplementation:
18571 ResetObjCLayout(cast<ObjCImplementationDecl>(DC)->getClassInterface());
18576 RecordDecl *Record = dyn_cast<RecordDecl>(EnclosingDecl);
18577 CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(EnclosingDecl);
18581 unsigned NumNamedMembers = 0;
18583 for (
const auto *I : Record->
decls()) {
18584 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
18585 if (IFD->getDeclName())
18602 RecFields.push_back(FD);
18622 bool IsLastField = (i + 1 == Fields.end());
18631 (Record || isa<ObjCContainerDecl>(EnclosingDecl))) {
18637 unsigned DiagID = 0;
18638 if (!Record->
isUnion() && !IsLastField) {
18641 Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
18645 }
else if (Record->
isUnion())
18646 DiagID = getLangOpts().MicrosoftExt
18647 ? diag::ext_flexible_array_union_ms
18648 : getLangOpts().CPlusPlus
18649 ? diag::ext_flexible_array_union_gnu
18650 : diag::err_flexible_array_union;
18651 else if (NumNamedMembers < 1)
18652 DiagID = getLangOpts().MicrosoftExt
18653 ? diag::ext_flexible_array_empty_aggregate_ms
18654 : getLangOpts().CPlusPlus
18655 ? diag::ext_flexible_array_empty_aggregate_gnu
18656 : diag::err_flexible_array_empty_aggregate;
18666 if (CXXRecord && CXXRecord->getNumVBases() != 0)
18669 if (!getLangOpts().
C99)
18680 Diag(FD->
getLocation(), diag::err_flexible_array_has_nontrivial_dtor)
18694 RequireCompleteSizedType(
18696 diag::err_field_incomplete_or_sizeless)) {
18721 if (isa<ObjCContainerDecl>(EnclosingDecl) &&
18723 diag::err_abstract_type_in_decl,
18724 AbstractIvarType)) {
18738 }
else if (Record && Record->
isUnion() &&
18740 getSourceManager().isInSystemHeader(FD->
getLocation()) &&
18750 FD->
addAttr(UnavailableAttr::CreateImplicit(
18751 Context,
"", UnavailableAttr::IR_ARCFieldWithOwnership,
18753 }
else if (getLangOpts().ObjC &&
18770 if (Record && !getLangOpts().
CPlusPlus &&
18771 !shouldIgnoreForRecordTriviality(FD)) {
18793 if (RT->getDecl()->getArgPassingRestrictions() ==
18809 bool Completed =
false;
18811 if (!CXXRecord->isInvalidDecl()) {
18814 I = CXXRecord->conversion_begin(),
18815 E = CXXRecord->conversion_end(); I != E; ++I)
18816 I.setAccess((*I)->getAccess());
18820 AddImplicitlyDeclaredMembersToClass(CXXRecord);
18822 if (!CXXRecord->isDependentType()) {
18823 if (!CXXRecord->isInvalidDecl()) {
18827 if (CXXRecord->getNumVBases()) {
18829 CXXRecord->getFinalOverriders(FinalOverriders);
18831 for (CXXFinalOverriderMap::iterator M = FinalOverriders.begin(),
18832 MEnd = FinalOverriders.end();
18835 SOEnd = M->second.end();
18836 SO != SOEnd; ++SO) {
18837 assert(SO->second.size() > 0 &&
18838 "Virtual function without overriding functions?");
18839 if (SO->second.size() == 1)
18847 << (
const NamedDecl *)M->first << Record;
18848 Diag(M->first->getLocation(),
18849 diag::note_overridden_virtual_function);
18851 OM = SO->second.begin(),
18852 OMEnd = SO->second.end();
18854 Diag(OM->Method->getLocation(), diag::note_final_overrider)
18855 << (
const NamedDecl *)M->first << OM->Method->getParent();
18860 CXXRecord->completeDefinition(&FinalOverriders);
18873 ProcessDeclAttributeList(S, Record, Attrs);
18876 auto IsFunctionPointerOrForwardDecl = [&](
const Decl *D) {
18877 const FieldDecl *FD = dyn_cast<FieldDecl>(D);
18890 if (
const auto *TD = dyn_cast<TagDecl>(D))
18891 return !TD->isCompleteDefinition();
18895 if (isa<PointerType>(FieldType)) {
18905 (Record->
hasAttr<RandomizeLayoutAttr>() ||
18906 (!Record->
hasAttr<NoRandomizeLayoutAttr>() &&
18907 llvm::all_of(Record->
decls(), IsFunctionPointerOrForwardDecl))) &&
18908 !Record->
isUnion() && !getLangOpts().RandstructSeed.empty() &&
18918 auto *Dtor = CXXRecord->getDestructor();
18919 if (Dtor && Dtor->isImplicit() &&
18920 ShouldDeleteSpecialMember(Dtor, CXXDestructor)) {
18921 CXXRecord->setImplicitDestructorIsDeleted();
18922 SetDeclDeleted(Dtor, CXXRecord->getLocation());
18927 CheckAlignasUnderalignment(Record);
18929 if (
const MSInheritanceAttr *IA = Record->
getAttr<MSInheritanceAttr>())
18930 checkMSInheritanceAttrOnDefinition(cast<CXXRecordDecl>(Record),
18931 IA->getRange(), IA->getBestCase(),
18932 IA->getInheritanceModel());
18938 bool CheckForZeroSize;
18940 CheckForZeroSize =
true;
18945 CXXRecord->getLexicalDeclContext()->isExternCContext() &&
18946 !CXXRecord->isDependentType() && !inTemplateInstantiation() &&
18947 CXXRecord->isCLike();
18949 if (CheckForZeroSize) {
18950 bool ZeroSize =
true;
18951 bool IsEmpty =
true;
18952 unsigned NonBitFields = 0;
18955 (NonBitFields == 0 || ZeroSize) && I != E; ++I) {
18957 if (I->isUnnamedBitfield()) {
18958 if (!I->isZeroLengthBitField(Context))
18962 QualType FieldType = I->getType();
18974 diag::warn_zero_size_struct_union_in_extern_c :
18975 diag::warn_zero_size_struct_union_compat)
18976 << IsEmpty << Record->
isUnion() << (NonBitFields > 1);
18981 if (NonBitFields == 0 && !getLangOpts().CPlusPlus) {
18982 Diag(RecLoc, IsEmpty ? diag::ext_empty_struct_union :
18983 diag::ext_no_named_members_in_struct_union)
18991 ID->setEndOfDefinitionLoc(RBrac);
18993 for (
unsigned i = 0, e = RecFields.size(); i != e; ++i) {
18995 ID->addDecl(ClsFields[i]);
18999 if (
ID->getSuperClass())
19000 DiagnoseDuplicateIvars(
ID,
ID->getSuperClass());
19002 dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
19003 assert(IMPDecl &&
"ActOnFields - missing ObjCImplementationDecl");
19004 for (
unsigned I = 0, N = RecFields.size(); I != N; ++I)
19008 CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
19009 IMPDecl->setIvarLBraceLoc(LBrac);
19010 IMPDecl->setIvarRBraceLoc(RBrac);
19012 dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
19020 for (
unsigned i = 0, e = RecFields.size(); i != e; ++i) {
19024 Diag(ClsFields[i]->getLocation(),
19025 diag::err_duplicate_ivar_declaration);
19026 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
19032 Diag(ClsFields[i]->getLocation(),
19033 diag::err_duplicate_ivar_declaration);
19034 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
19040 CDecl->addDecl(ClsFields[i]);
19042 CDecl->setIvarLBraceLoc(LBrac);
19043 CDecl->setIvarRBraceLoc(RBrac);
19054 "Integral type required!");
19057 if (
Value.isUnsigned() ||
Value.isNonNegative()) {
19060 return Value.getActiveBits() <= BitWidth;
19062 return Value.getMinSignedBits() <= BitWidth;
19072 const unsigned NumTypes = 4;
19073 QualType SignedIntegralTypes[NumTypes] = {
19076 QualType UnsignedIntegralTypes[NumTypes] = {
19083 : UnsignedIntegralTypes;
19084 for (
unsigned I = 0; I != NumTypes; ++I)
19100 if (Val && DiagnoseUnexpandedParameterPack(Val, UPPC_EnumeratorValue))
19104 Val = DefaultLvalueConversion(Val).get();
19113 if (getLangOpts().
CPlusPlus11 && Enum->isFixed()) {
19117 EltTy = Enum->getIntegerType();
19124 Val = Converted.
get();
19127 VerifyIntegerConstantExpression(Val, &EnumVal, AllowFold)
19131 if (Enum->isComplete()) {
19132 EltTy = Enum->getIntegerType();
19141 .isWindowsMSVCEnvironment()) {
19142 Diag(IdLoc, diag::ext_enumerator_too_large) << EltTy;
19144 Diag(IdLoc, diag::err_enumerator_too_large) << EltTy;
19149 Val = ImpCastExprToType(Val, EltTy,
19168 Diag(IdLoc, diag::ext_enum_value_not_int)
19170 << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
19173 Val = ImpCastExprToType(Val, Context.
IntTy, CK_IntegralCast).get();
19182 if (Enum->isDependentType())
19184 else if (!LastEnumConst) {
19193 if (Enum->isFixed()) {
19194 EltTy = Enum->getIntegerType();
19197 EltTy = Context.
IntTy;
19203 EltTy = LastEnumConst->
getType();
19206 if (EnumVal < LastEnumConst->getInitVal()) {
19218 if (T.
isNull() || Enum->isFixed()) {
19222 EnumVal = EnumVal.zext(EnumVal.getBitWidth() * 2);
19224 if (Enum->isFixed())
19226 Diag(IdLoc, diag::err_enumerator_wrapped)
19230 Diag(IdLoc, diag::ext_enumerator_increment_too_large)
19241 EnumVal = EnumVal.zextOrTrunc(Context.
getIntWidth(EltTy));
19250 Diag(IdLoc, diag::warn_enum_value_overflow);
19254 Diag(IdLoc, diag::ext_enum_value_not_int)
19263 EnumVal = EnumVal.extOrTrunc(Context.
getIntWidth(EltTy));
19273 if (!(getLangOpts().Modules || getLangOpts().ModulesLocalVisibility) ||
19280 NamedDecl *PrevDecl = LookupSingleName(S, II, IILoc, LookupOrdinaryName,
19281 forRedeclarationInCurContext());
19282 auto *PrevECD = dyn_cast_or_null<EnumConstantDecl>(PrevDecl);
19286 EnumDecl *PrevED = cast<EnumDecl>(PrevECD->getDeclContext());
19288 if (!PrevED->
getDeclName() && !hasVisibleDefinition(PrevED, &Hidden)) {
19301 EnumDecl *TheEnumDecl = cast<EnumDecl>(theEnumDecl);
19303 cast_or_null<EnumConstantDecl>(lastEnumConst);
19307 S = getNonFieldDeclScope(S);
19311 LookupResult R(*
this,
Id, IdLoc, LookupOrdinaryName, ForVisibleRedeclaration);
19317 DiagnoseTemplateParameterShadow(IdLoc, PrevDecl);
19319 PrevDecl =
nullptr;
19332 CheckEnumConstant(TheEnumDecl, LastEnumConst, IdLoc,
Id, Val);
19337 if (!TheEnumDecl->
isScoped() && isa<ValueDecl>(PrevDecl)) {
19339 CheckShadow(New, PrevDecl, R);
19344 assert((getLangOpts().
CPlusPlus || !isa<TagDecl>(PrevDecl)) &&
19345 "Received TagDecl when not in C++!");
19346 if (!isa<TagDecl>(PrevDecl) && isDeclInScope(PrevDecl, CurContext, S)) {
19347 if (isa<EnumConstantDecl>(PrevDecl))
19348 Diag(IdLoc, diag::err_redefinition_of_enumerator) <<
Id;
19350 Diag(IdLoc, diag::err_redefinition) <<
Id;
19351 notePreviousDefinition(PrevDecl, IdLoc);
19357 ProcessDeclAttributeList(S, New, Attrs);
19358 AddPragmaAttributes(S, New);
19362 PushOnScopeChains(New, S);
19364 ActOnDocumentableDecl(New);
19382 if (!BO->isAdditiveOp())
19390 InitExpr = BO->getLHS();
19394 DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(InitExpr);
19414 if (!Enum->getIdentifier())
19418 if (Enum->getNumPositiveBits() > 63 || Enum->getNumNegativeBits() > 64)
19421 if (S.
Diags.
isIgnored(diag::warn_duplicate_enum_values, Enum->getLocation()))
19427 typedef llvm::PointerUnion<EnumConstantDecl*, ECDVector*> DeclOrVector;
19430 typedef std::unordered_map<int64_t, DeclOrVector> ValueToVectorMap;
19435 return Val.isSigned() ? Val.getSExtValue() : Val.getZExtValue();
19438 DuplicatesVector DupVector;
19439 ValueToVectorMap EnumMap;
19443 for (
auto *Element : Elements) {
19457 EnumMap.insert({EnumConstantToKey(ECD), ECD});
19460 if (EnumMap.size() == 0)
19464 for (
auto *Element : Elements) {
19470 auto Iter = EnumMap.find(EnumConstantToKey(ECD));
19471 if (Iter == EnumMap.end())
19474 DeclOrVector& Entry = Iter->second;
19481 auto Vec = std::make_unique<ECDVector>();
19483 Vec->push_back(ECD);
19490 DupVector.emplace_back(std::move(Vec));
19494 ECDVector *Vec = Entry.get<ECDVector*>();
19496 if (*Vec->begin() == ECD)
19499 Vec->push_back(ECD);
19503 for (
const auto &Vec : DupVector) {
19504 assert(Vec->size() > 1 &&
"ECDVector should have at least 2 elements.");
19507 auto *FirstECD = Vec->front();
19508 S.
Diag(FirstECD->getLocation(), diag::warn_duplicate_enum_values)
19509 << FirstECD <<
toString(FirstECD->getInitVal(), 10)
19510 << FirstECD->getSourceRange();
19514 for (
auto *ECD : llvm::drop_begin(*Vec))
19515 S.
Diag(ECD->getLocation(), diag::note_duplicate_element)
19516 << ECD <<
toString(ECD->getInitVal(), 10)
19517 << ECD->getSourceRange();
19522 bool AllowMask)
const {
19523 assert(ED->
isClosedFlag() &&
"looking for value in non-flag or open enum");
19526 auto R = FlagBitsCache.insert(std::make_pair(ED,
llvm::APInt()));
19531 const auto &EVal = E->getInitVal();
19533 if (EVal.isPowerOf2())
19534 FlagBits = FlagBits.zext(EVal.getBitWidth()) | EVal;
19546 llvm::APInt FlagMask = ~FlagBits.zextOrTrunc(Val.getBitWidth());
19547 return !(FlagMask & Val) || (AllowMask && !(FlagMask & ~Val));
19553 EnumDecl *Enum = cast<EnumDecl>(EnumDeclX);
19556 ProcessDeclAttributeList(S, Enum, Attrs);
19558 if (Enum->isDependentType()) {
19559 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
19561 cast_or_null<EnumConstantDecl>(Elements[i]);
19562 if (!ECD)
continue;
19580 unsigned NumNegativeBits = 0;
19581 unsigned NumPositiveBits = 0;
19583 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
19585 cast_or_null<EnumConstantDecl>(Elements[i]);
19586 if (!ECD)
continue;
19591 if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
19594 unsigned ActiveBits = InitVal.getActiveBits();
19595 NumPositiveBits =
std::max({NumPositiveBits, ActiveBits, 1u});
19597 NumNegativeBits =
std::max(NumNegativeBits,
19598 (
unsigned)InitVal.getMinSignedBits());
19606 if (!NumPositiveBits && !NumNegativeBits)
19607 NumPositiveBits = 1;
19611 unsigned BestWidth;
19624 bool Packed = Enum->hasAttr<PackedAttr>();
19627 if (LangOpts.ShortEnums)
19632 if (Enum->isComplete()) {
19633 BestType = Enum->getIntegerType();
19637 BestPromotionType = BestType;
19641 else if (NumNegativeBits) {
19645 if (Packed && NumNegativeBits <= CharWidth && NumPositiveBits < CharWidth) {
19647 BestWidth = CharWidth;
19648 }
else if (Packed && NumNegativeBits <= ShortWidth &&
19649 NumPositiveBits < ShortWidth) {
19651 BestWidth = ShortWidth;
19652 }
else if (NumNegativeBits <= IntWidth && NumPositiveBits < IntWidth) {
19653 BestType = Context.
IntTy;
19654 BestWidth = IntWidth;
19658 if (NumNegativeBits <= BestWidth && NumPositiveBits < BestWidth) {
19659 BestType = Context.
LongTy;
19663 if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
19664 Diag(Enum->getLocation(), diag::ext_enum_too_large);
19668 BestPromotionType = (BestWidth <= IntWidth ? Context.
IntTy : BestType);
19673 if (Packed && NumPositiveBits <= CharWidth) {
19675 BestPromotionType = Context.
IntTy;
19676 BestWidth = CharWidth;
19677 }
else if (Packed && NumPositiveBits <= ShortWidth) {
19679 BestPromotionType = Context.
IntTy;
19680 BestWidth = ShortWidth;
19681 }
else if (NumPositiveBits <= IntWidth) {
19683 BestWidth = IntWidth;
19685 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
19687 }
else if (NumPositiveBits <=
19691 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
19695 assert(NumPositiveBits <= BestWidth &&
19696 "How could an initializer get larger than ULL?");
19699 = (NumPositiveBits == BestWidth || !getLangOpts().CPlusPlus)
19706 for (
auto *D : Elements) {
19707 auto *ECD = cast_or_null<EnumConstantDecl>(D);
19708 if (!ECD)
continue;
19725 !Enum->isFixed() &&
19727 NewTy = Context.
IntTy;
19728 NewWidth = IntWidth;
19730 }
else if (ECD->getType() == BestType) {
19740 NewWidth = BestWidth;
19745 InitVal = InitVal.extOrTrunc(NewWidth);
19746 InitVal.setIsSigned(NewSign);
19747 ECD->setInitVal(InitVal);
19750 if (ECD->getInitExpr() &&
19751 !Context.
hasSameType(NewTy, ECD->getInitExpr()->getType()))
19753 Context, NewTy, CK_IntegralCast, ECD->getInitExpr(),
19761 ECD->setType(NewTy);
19764 Enum->completeDefinition(BestType, BestPromotionType,
19765 NumPositiveBits, NumNegativeBits);
19769 if (Enum->isClosedFlag()) {
19770 for (
Decl *D : Elements) {
19772 if (!ECD)
continue;
19775 if (InitVal != 0 && !InitVal.isPowerOf2() &&
19776 !IsValueInFlagEnum(Enum, InitVal,
true))
19783 if (Enum->hasAttrs())
19784 CheckAlignasUnderalignment(Enum);
19793 AsmString, StartLoc,
19795 CurContext->addDecl(New);
19810 NamedDecl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
19811 LookupOrdinaryName);
19814 AsmLabelAttr *
Attr = AsmLabelAttr::CreateImplicit(
19815 Context, AliasName->
getName(),
true, Info);
19821 if (PrevDecl && (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl))) {
19825 Diag(PrevDecl->
getLocation(), diag::warn_redefine_extname_not_applied)
19826 << (isa<FunctionDecl>(PrevDecl) ? 0 : 1) << PrevDecl;
19829 (
void)ExtnameUndeclaredIdentifiers.insert(std::make_pair(Name,
Attr));
19835 Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc, LookupOrdinaryName);
19840 (void)WeakUndeclaredIdentifiers[Name].insert(
WeakInfo(
nullptr, NameLoc));
19849 Decl *PrevDecl = LookupSingleName(TUScope, AliasName, AliasNameLoc,
19850 LookupOrdinaryName);
19853 if (PrevDecl && (isa<FunctionDecl>(PrevDecl) || isa<VarDecl>(PrevDecl))) {
19854 if (!PrevDecl->
hasAttr<AliasAttr>())
19855 if (
NamedDecl *ND = dyn_cast<NamedDecl>(PrevDecl))
19856 DeclApplyPragmaWeak(TUScope, ND, W);
19858 (void)WeakUndeclaredIdentifiers[AliasName].insert(W);
19863 return (dyn_cast_or_null<ObjCContainerDecl>(CurContext));
19868 assert(FD &&
"Expected non-null FunctionDecl");
19872 if (LangOpts.SYCLIsDevice && FD->
hasAttr<SYCLKernelAttr>())
19873 return FunctionEmissionStatus::Emitted;
19877 return FunctionEmissionStatus::TemplateDiscarded;
19880 auto IsEmittedForExternalSymbol = [
this, FD]() {
19887 getASTContext().GetGVALinkageForFunction(Def));
19890 if (LangOpts.OpenMPIsDevice) {
19893 std::optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
19900 if (*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
19901 return FunctionEmissionStatus::OMPDiscarded;
19904 if (isInOpenMPDeclareTargetContext() || DevTy)
19905 if (IsEmittedForExternalSymbol())
19906 return FunctionEmissionStatus::Emitted;
19910 return FunctionEmissionStatus::OMPDiscarded;
19911 }
else if (LangOpts.OpenMP > 45) {
19915 std::optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
19918 if (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost)
19919 return FunctionEmissionStatus::OMPDiscarded;
19922 if (Final && LangOpts.OpenMP && !LangOpts.CUDA)
19923 return FunctionEmissionStatus::Emitted;
19925 if (LangOpts.CUDA) {
19932 return FunctionEmissionStatus::CUDADiscarded;
19933 if (!LangOpts.CUDAIsDevice &&
19935 return FunctionEmissionStatus::CUDADiscarded;
19937 if (IsEmittedForExternalSymbol())
19938 return FunctionEmissionStatus::Emitted;
19954 return LangOpts.CUDA && !LangOpts.CUDAIsDevice &&
19955 IdentifyCUDATarget(Callee) == CFT_Global;